Skip to content

Commit 37c6d0b

Browse files
Remove bare exceptions from 'pandas/tests' to decrease flake8 E722 warnings
1 parent e45a6c1 commit 37c6d0b

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

pandas/tests/indexing/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def get_result(self, obj, method, key, axis):
151151
with catch_warnings(record=True):
152152
try:
153153
xp = getattr(obj, method).__getitem__(_axify(obj, key, axis))
154-
except:
154+
except Exception:
155155
xp = getattr(obj, method).__getitem__(key)
156156

157157
return xp
@@ -214,7 +214,7 @@ def _print(result, error=None):
214214

215215
try:
216216
xp = self.get_result(obj, method2, k2, a)
217-
except:
217+
except Exception:
218218
result = 'no comp'
219219
_print(result)
220220
return

pandas/tests/io/formats/test_format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def has_horizontally_truncated_repr(df):
7070
try: # Check header row
7171
fst_line = np.array(repr(df).splitlines()[0].split())
7272
cand_col = np.where(fst_line == '...')[0][0]
73-
except:
73+
except Exception:
7474
return False
7575
# Make sure each row has this ... in the same place
7676
r = repr(df)
@@ -452,7 +452,7 @@ def test_to_string_repr_unicode(self):
452452
for line in rs[1:]:
453453
try:
454454
line = line.decode(get_option("display.encoding"))
455-
except:
455+
except Exception:
456456
pass
457457
if not line.startswith('dtype:'):
458458
assert len(line) == line_len

pandas/tests/io/test_pytables.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ def safe_remove(path):
5151
if path is not None:
5252
try:
5353
os.remove(path)
54-
except:
54+
except OSError:
5555
pass
5656

5757

5858
def safe_close(store):
5959
try:
6060
if store is not None:
6161
store.close()
62-
except:
62+
except Exception:
6363
pass
6464

6565

@@ -117,7 +117,7 @@ def _maybe_remove(store, key):
117117
no content from previous tests using the same table name."""
118118
try:
119119
store.remove(key)
120-
except:
120+
except Exception:
121121
pass
122122

123123

@@ -4621,7 +4621,7 @@ def do_copy(f, new_f=None, keys=None,
46214621
safe_close(tstore)
46224622
try:
46234623
os.close(fd)
4624-
except:
4624+
except ValueError:
46254625
pass
46264626
safe_remove(new_f)
46274627

pandas/tests/io/test_sql.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ def test_read_procedure(self):
17901790
try:
17911791
r1 = connection.execute(proc) # noqa
17921792
trans.commit()
1793-
except:
1793+
except Exception:
17941794
trans.rollback()
17951795
raise
17961796

@@ -2375,7 +2375,7 @@ def setup_class(cls):
23752375
# No real user should allow root access with a blank password.
23762376
pymysql.connect(host='localhost', user='root', passwd='',
23772377
db='pandas_nosetest')
2378-
except:
2378+
except Exception:
23792379
pass
23802380
else:
23812381
return
@@ -2402,7 +2402,7 @@ def setup_method(self, request, datapath):
24022402
# No real user should allow root access with a blank password.
24032403
self.conn = pymysql.connect(host='localhost', user='root',
24042404
passwd='', db='pandas_nosetest')
2405-
except:
2405+
except Exception:
24062406
pass
24072407
else:
24082408
return

pandas/tests/test_multilevel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ def f():
13751375

13761376
try:
13771377
df = f()
1378-
except:
1378+
except Exception:
13791379
pass
13801380
assert (df['foo', 'one'] == 0).all()
13811381

pandas/tests/test_nanops.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ def _coerce_tds(targ, res):
141141
if axis != 0 and hasattr(
142142
targ, 'shape') and targ.ndim and targ.shape != res.shape:
143143
res = np.split(res, [targ.shape[0]], axis=0)[0]
144-
except:
144+
except (np.ValueError, IndexError):
145145
targ, res = _coerce_tds(targ, res)
146146

147147
try:
148148
tm.assert_almost_equal(targ, res, check_dtype=check_dtype)
149-
except:
149+
except Exception:
150150

151151
# handle timedelta dtypes
152152
if hasattr(targ, 'dtype') and targ.dtype == 'm8[ns]':
@@ -167,11 +167,11 @@ def _coerce_tds(targ, res):
167167
else:
168168
try:
169169
res = res.astype('c16')
170-
except:
170+
except Exception:
171171
res = res.astype('f8')
172172
try:
173173
targ = targ.astype('c16')
174-
except:
174+
except Exception:
175175
targ = targ.astype('f8')
176176
# there should never be a case where numpy returns an object
177177
# but nanops doesn't, so make that an exception

pandas/tests/test_panel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,13 @@ def check_op(op, name):
335335
for op in ops:
336336
try:
337337
check_op(getattr(operator, op), op)
338-
except:
338+
except (AttributeError, KeyError):
339339
pprint_thing("Failing operation: %r" % op)
340340
raise
341341
if compat.PY3:
342342
try:
343343
check_op(operator.truediv, 'div')
344-
except:
344+
except (AttributeError, KeyError):
345345
pprint_thing("Failing operation: %r" % 'div')
346346
raise
347347

pandas/tests/test_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ def test_slice(self):
26602660
expected = Series([s[start:stop:step] if not isna(s) else NA
26612661
for s in values])
26622662
tm.assert_series_equal(result, expected)
2663-
except:
2663+
except IndexError:
26642664
print('failed on %s:%s:%s' % (start, stop, step))
26652665
raise
26662666

0 commit comments

Comments
 (0)