Skip to content
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

STYLE: Specify bare exceptions in pandas/tests #23370

Merged
merged 22 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cd65d8e
Fix issue #22872 - Capture specific exceptions
alexander-ponomaroff Oct 27, 2018
066cdcf
Some fixes
alexander-ponomaroff Oct 27, 2018
318dd54
Further fixes
alexander-ponomaroff Oct 27, 2018
677b707
Test if the problem is in common.py line 217
alexander-ponomaroff Oct 27, 2018
fa0b03b
Issue confirmed line 217 of common.py, testing exceptions
alexander-ponomaroff Oct 27, 2018
2f57297
Working through exceptions
alexander-ponomaroff Oct 27, 2018
6cca7d7
Working through exceptions
alexander-ponomaroff Oct 27, 2018
6967323
Fix final bare excepts and stop ignoring E722
alexander-ponomaroff Oct 27, 2018
91c8af2
Added assertion error to line 217 of common.py
alexander-ponomaroff Oct 27, 2018
3fc4499
Line 217 still problematic
alexander-ponomaroff Oct 27, 2018
12b8c34
Rebase
alexander-ponomaroff Oct 31, 2018
f055a09
Update pymysql errors
alexander-ponomaroff Nov 5, 2018
4f08510
Merge branch 'master' into issue-22872
alexander-ponomaroff Nov 5, 2018
85e1c9c
Rebase
alexander-ponomaroff Nov 8, 2018
74ce78c
Merge conflict fix
alexander-ponomaroff Nov 8, 2018
39944b6
isort Run on pandas, test_sql.py removed from setup.cfg exclusion list
alexander-ponomaroff Nov 8, 2018
c276bd3
merge
alexander-ponomaroff Nov 8, 2018
48ad6f0
Reverted isort changes
alexander-ponomaroff Nov 8, 2018
c55692f
import pymysql in the beginning of function
alexander-ponomaroff Nov 10, 2018
ff36b21
Remove empty line 1819
alexander-ponomaroff Nov 13, 2018
bd3e656
Merge branch 'master' into PR_TOOL_MERGE_PR_23370
jreback Nov 18, 2018
6a86779
Merge branch 'master' into PR_TOOL_MERGE_PR_23370
jreback Nov 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pep8speaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pycodestyle:
- W503, # line break before binary operator
- W504, # line break after binary operator
- E402, # module level import not at top of file
- E722, # do not use bare except
- E731, # do not assign a lambda expression, use a def
- C406, # Unnecessary list literal - rewrite as a dict literal.
- C408, # Unnecessary dict call - rewrite as a literal.
Expand Down
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
4 changes: 2 additions & 2 deletions pandas/tests/indexing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_result(self, obj, method, key, axis):
with catch_warnings(record=True):
try:
xp = getattr(obj, method).__getitem__(_axify(obj, key, axis))
except:
except AttributeError:
xp = getattr(obj, method).__getitem__(key)

return xp
Expand Down Expand Up @@ -219,7 +219,7 @@ def _print(result, error=None):

try:
xp = self.get_result(obj, method2, k2, a)
except:
except Exception:
result = 'no comp'
_print(result)
return
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def has_horizontally_truncated_repr(df):
try: # Check header row
fst_line = np.array(repr(df).splitlines()[0].split())
cand_col = np.where(fst_line == '...')[0][0]
except:
except IndexError:
return False
# Make sure each row has this ... in the same place
r = repr(df)
Expand Down Expand Up @@ -452,7 +452,7 @@ def test_to_string_repr_unicode(self):
for line in rs[1:]:
try:
line = line.decode(get_option("display.encoding"))
except:
except AttributeError:
pass
if not line.startswith('dtype:'):
assert len(line) == line_len
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def safe_remove(path):
if path is not None:
try:
os.remove(path)
except:
except OSError:
pass


def safe_close(store):
try:
if store is not None:
store.close()
except:
except IOError:
pass


Expand Down Expand Up @@ -117,7 +117,7 @@ def _maybe_remove(store, key):
no content from previous tests using the same table name."""
try:
store.remove(key)
except:
except (ValueError, KeyError):
pass


Expand Down Expand Up @@ -4595,7 +4595,7 @@ def do_copy(f, new_f=None, keys=None,
safe_close(tstore)
try:
os.close(fd)
except:
except (OSError, ValueError):
pass
safe_remove(new_f)

Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1787,10 +1787,12 @@ def test_read_procedure(self):

connection = self.conn.connect()
trans = connection.begin()

import pymysql
alexander-ponomaroff marked this conversation as resolved.
Show resolved Hide resolved
try:
r1 = connection.execute(proc) # noqa
trans.commit()
except:
except pymysql.Error:
datapythonista marked this conversation as resolved.
Show resolved Hide resolved
trans.rollback()
raise

Expand Down Expand Up @@ -2375,7 +2377,7 @@ def setup_class(cls):
# No real user should allow root access with a blank password.
pymysql.connect(host='localhost', user='root', passwd='',
db='pandas_nosetest')
except:
except pymysql.Error:
pass
else:
return
Expand All @@ -2402,7 +2404,7 @@ def setup_method(self, request, datapath):
# No real user should allow root access with a blank password.
self.conn = pymysql.connect(host='localhost', user='root',
passwd='', db='pandas_nosetest')
except:
except pymysql.Error:
pass
else:
return
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ def f():

try:
df = f()
except:
except ValueError:
pass
assert (df['foo', 'one'] == 0).all()

Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/test_nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def _coerce_tds(targ, res):
if axis != 0 and hasattr(
targ, 'shape') and targ.ndim and targ.shape != res.shape:
res = np.split(res, [targ.shape[0]], axis=0)[0]
except:
except (ValueError, IndexError):
targ, res = _coerce_tds(targ, res)

try:
tm.assert_almost_equal(targ, res, check_dtype=check_dtype)
except:
except AssertionError:

# handle timedelta dtypes
if hasattr(targ, 'dtype') and targ.dtype == 'm8[ns]':
Expand All @@ -167,11 +167,11 @@ def _coerce_tds(targ, res):
else:
try:
res = res.astype('c16')
except:
except RuntimeError:
res = res.astype('f8')
try:
targ = targ.astype('c16')
except:
except RuntimeError:
targ = targ.astype('f8')
# there should never be a case where numpy returns an object
# but nanops doesn't, so make that an exception
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ def check_op(op, name):
for op in ops:
try:
check_op(getattr(operator, op), op)
except:
except AttributeError:
pprint_thing("Failing operation: %r" % op)
raise
if compat.PY3:
try:
check_op(operator.truediv, 'div')
except:
except AttributeError:
pprint_thing("Failing operation: %r" % 'div')
raise

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ def test_slice(self):
expected = Series([s[start:stop:step] if not isna(s) else NA
for s in values])
tm.assert_series_equal(result, expected)
except:
except IndexError:
print('failed on %s:%s:%s' % (start, stop, step))
raise

Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ignore =
W503, # line break before binary operator
W504, # line break after binary operator
E402, # module level import not at top of file
E722, # do not use bare except
E731, # do not assign a lambda expression, use a def
C406, # Unnecessary list literal - rewrite as a dict literal.
C408, # Unnecessary dict call - rewrite as a literal.
Expand Down