Skip to content

STYLE: Fixing #18419 - Fixing flake8 issues to allow for >3.4.1 support #22625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,19 +565,19 @@ def linkcode_resolve(domain, info):
for part in fullname.split('.'):
try:
obj = getattr(obj, part)
except:
except AttributeError:
return None

try:
fn = inspect.getsourcefile(obj)
except:
except TypeError:
fn = None
if not fn:
return None

try:
source, lineno = inspect.getsourcelines(obj)
except:
except OSError:
lineno = None

if lineno:
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ Build Changes

- Building pandas for development now requires ``cython >= 0.28.2`` (:issue:`21688`)
- Testing pandas now requires ``hypothesis>=3.58`` (:issue:22280). You can find `the Hypothesis docs here <https://hypothesis.readthedocs.io/en/latest/index.html>`_, and a pandas-specific introduction :ref:`in the contributing guide <using-hypothesis>` .
-
- ci/lint.sh now supports flake8 > 3.4.1 (:issue:`18419`)

Other
^^^^^
Expand Down
24 changes: 10 additions & 14 deletions pandas/compat/pickle_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load_reduce(self):
cls = args[0]
stack[-1] = object.__new__(cls)
return
except:
except Exception:
pass

# try to re-encode the arguments
Expand All @@ -44,7 +44,7 @@ def load_reduce(self):
try:
stack[-1] = func(*args)
return
except:
except Exception:
pass

# unknown exception, re-raise
Expand Down Expand Up @@ -182,7 +182,7 @@ def load_newobj_ex(self):

try:
Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex
except:
except Exception:
pass


Expand All @@ -200,15 +200,11 @@ def load(fh, encoding=None, compat=False, is_verbose=False):
compat: provide Series compatibility mode, boolean, default False
is_verbose: show exception output
"""
fh.seek(0)
if encoding is not None:
up = Unpickler(fh, encoding=encoding)
else:
up = Unpickler(fh)
up.is_verbose = is_verbose

try:
fh.seek(0)
if encoding is not None:
up = Unpickler(fh, encoding=encoding)
else:
up = Unpickler(fh)
up.is_verbose = is_verbose

return up.load()
except:
raise
return up.load()
4 changes: 2 additions & 2 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ def visit_Assign(self, node, **kwargs):
return self.visit(cmpr)

def visit_Subscript(self, node, **kwargs):
# only allow simple suscripts
# only allow simple subscripts

value = self.visit(node.value)
slobj = self.visit(node.slice)
try:
value = value.value
except:
except AttributeError:
pass

try:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def is_timedelta64_dtype(arr_or_dtype):
return False
try:
tipo = _get_dtype_type(arr_or_dtype)
except:
except Exception:
return False
return issubclass(tipo, np.timedelta64)

Expand Down
8 changes: 3 additions & 5 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ def construct_from_string(cls, string):
try:
if string == 'category':
return cls()
except:
pass

raise TypeError("cannot construct a CategoricalDtype")
except Exception:
TypeError("cannot construct a CategoricalDtype")

@staticmethod
def validate_ordered(ordered):
Expand Down Expand Up @@ -499,7 +497,7 @@ def __new__(cls, unit=None, tz=None):
if m is not None:
unit = m.groupdict()['unit']
tz = m.groupdict()['tz']
except:
except Exception:
raise ValueError("could not construct DatetimeTZDtype")

elif isinstance(unit, compat.string_types):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3187,7 +3187,7 @@ def _ensure_valid_index(self, value):
if not len(self.index) and is_list_like(value):
try:
value = Series(value)
except:
except ValueError:
raise ValueError('Cannot set a frame with no defined index '
'and a value that cannot be converted to a '
'Series')
Expand Down Expand Up @@ -7621,7 +7621,7 @@ def convert(v):
values = np.array([convert(v) for v in values])
else:
values = convert(values)
except:
except Exception:
values = convert(values)

else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def searchsorted(self, v, side='left', sorter=None):
# https://github.com/numpy/numpy/issues/5370
try:
v = self.dtype.type(v)
except:
except Exception:
pass
return super(FrozenNDArray, self).searchsorted(
v, side=side, sorter=sorter)
Expand Down
15 changes: 7 additions & 8 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,12 @@ def _try_mi(k):
return _try_mi(key)
except (KeyError):
raise
except:
except Exception:
pass

try:
return _try_mi(Timestamp(key))
except:
except Exception:
pass

raise InvalidIndexError(key)
Expand Down Expand Up @@ -1640,7 +1640,7 @@ def append(self, other):
# if all(isinstance(x, MultiIndex) for x in other):
try:
return MultiIndex.from_tuples(new_tuples, names=self.names)
except:
except TypeError:
return Index(new_tuples)

def argsort(self, *args, **kwargs):
Expand Down Expand Up @@ -2269,8 +2269,7 @@ def maybe_droplevels(indexer, levels, drop_level):
for i in sorted(levels, reverse=True):
try:
new_index = new_index.droplevel(i)
except:

except ValueError:
# no dropping here
return orig_index
return new_index
Expand Down Expand Up @@ -2769,11 +2768,11 @@ def _convert_can_do_setop(self, other):
labels=[[]] * self.nlevels,
verify_integrity=False)
else:
msg = 'other must be a MultiIndex or a list of tuples'
try:
other = MultiIndex.from_tuples(other)
except:
raise TypeError(msg)
except TypeError:
raise TypeError('other must be a MultiIndex or a list '
'of tuples.')
else:
result_names = self.names if self.names == other.names else None
return other, result_names
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,7 @@ def _getitem_tuple(self, tup):
self._has_valid_tuple(tup)
try:
return self._getitem_lowerdim(tup)
except:
except IndexingError:
pass

retval = self.obj
Expand Down Expand Up @@ -2705,13 +2705,13 @@ def maybe_droplevels(index, key):
for _ in key:
try:
index = index.droplevel(0)
except:
except ValueError:
# we have dropped too much, so back out
return original_index
else:
try:
index = index.droplevel(0)
except:
except ValueError:
pass

return index
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,

newb = make_block(values, placement=self.mgr_locs,
klass=klass, ndim=self.ndim)
except:
except Exception:
if errors == 'raise':
raise
newb = self.copy() if copy else self
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def check_int_bool(self, inplace):
# a fill na type method
try:
m = missing.clean_fill_method(method)
except:
except ValueError:
m = None

if m is not None:
Expand All @@ -1157,7 +1157,7 @@ def check_int_bool(self, inplace):
# try an interp method
try:
m = missing.clean_interp_method(method, **kwargs)
except:
except ValueError:
m = None

if m is not None:
Expand Down Expand Up @@ -2438,7 +2438,7 @@ def set(self, locs, values, check=False):
try:
if (self.values[locs] == values).all():
return
except:
except Exception:
pass
try:
self.values[locs] = values
Expand Down Expand Up @@ -3172,7 +3172,7 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
def __len__(self):
try:
return self.sp_index.length
except:
except Exception:
return 0

def copy(self, deep=True, mgr=None):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def reduction(values, axis=None, skipna=True):
try:
result = getattr(values, meth)(axis, dtype=dtype_max)
result.fill(np.nan)
except:
except AttributeError:
result = np.nan
else:
result = getattr(values, meth)(axis)
Expand Down Expand Up @@ -813,7 +813,7 @@ def _ensure_numeric(x):
elif is_object_dtype(x):
try:
x = x.astype(np.complex128)
except:
except Exception:
x = x.astype(np.float64)
else:
if not np.any(x.imag):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ def na_op(x, y):
y = bool(y)
try:
result = libops.scalar_binop(x, y, op)
except:
except Exception:
raise TypeError("cannot compare a dtyped [{dtype}] array "
"with a scalar of type [{typ}]"
.format(dtype=x.dtype,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def __setstate__(self, state):
def __len__(self):
try:
return self.sp_index.length
except:
except Exception:
return 0

def __unicode__(self):
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _convert_listlike_datetimes(arg, box, format, name=None, tz=None,
if format == '%Y%m%d':
try:
result = _attempt_YYYYMMDD(arg, errors=errors)
except:
except Exception:
raise ValueError("cannot convert the input to "
"'%Y%m%d' date format")

Expand Down Expand Up @@ -331,7 +331,7 @@ def _adjust_to_origin(arg, origin, unit):
raise ValueError("unit must be 'D' for origin='julian'")
try:
arg = arg - j0
except:
except Exception:
raise ValueError("incompatible 'arg' type for given "
"'origin'='julian'")

Expand Down Expand Up @@ -728,21 +728,21 @@ def calc_with_mask(carg, mask):
# try intlike / strings that are ints
try:
return calc(arg.astype(np.int64))
except:
except Exception:
pass

# a float with actual np.nan
try:
carg = arg.astype(np.float64)
return calc_with_mask(carg, notna(carg))
except:
except Exception:
pass

# string with NaN-like
try:
mask = ~algorithms.isin(arg, list(tslib.nat_strings))
return calc_with_mask(arg, mask)
except:
except Exception:
pass

return None
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,7 @@ def _offset(window, center):
offset = (window - 1) / 2. if center else 0
try:
return int(offset)
except:
except ValueError:
return offset.astype(int)


Expand Down
2 changes: 1 addition & 1 deletion pandas/io/clipboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover
text, encoding=(kwargs.get('encoding') or
get_option('display.encoding'))
)
except:
except Exception:
pass

# Excel copies into clipboard with \t separation
Expand Down
Loading