diff --git a/pandas/tests/indexing/common.py b/pandas/tests/indexing/common.py index 127548bdaf106..d21db0113cc44 100644 --- a/pandas/tests/indexing/common.py +++ b/pandas/tests/indexing/common.py @@ -151,7 +151,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 @@ -214,7 +214,7 @@ def _print(result, error=None): try: xp = self.get_result(obj, method2, k2, a) - except: + except Exception: result = 'no comp' _print(result) return diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 03e830fb09ad6..293a0d6f20a7b 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -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) @@ -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 Exception: pass if not line.startswith('dtype:'): assert len(line) == line_len diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index ea5f1684c0695..8cfeb22c85e24 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -51,7 +51,7 @@ def safe_remove(path): if path is not None: try: os.remove(path) - except: + except OSError: pass @@ -59,7 +59,7 @@ def safe_close(store): try: if store is not None: store.close() - except: + except Exception: pass @@ -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 Exception: pass @@ -4621,7 +4621,7 @@ def do_copy(f, new_f=None, keys=None, safe_close(tstore) try: os.close(fd) - except: + except ValueError: pass safe_remove(new_f) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 237cc2936919e..a20ad2e7e6b62 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -1787,10 +1787,12 @@ def test_read_procedure(self): connection = self.conn.connect() trans = connection.begin() + + from pymysql.err import Error try: r1 = connection.execute(proc) # noqa trans.commit() - except: + except Error: trans.rollback() raise @@ -2370,12 +2372,13 @@ def setup_class(cls): # test connection import pymysql + from pymysql.err import Error try: # Try Travis defaults. # No real user should allow root access with a blank password. pymysql.connect(host='localhost', user='root', passwd='', db='pandas_nosetest') - except: + except Error: pass else: return @@ -2397,12 +2400,13 @@ def setup_class(cls): def setup_method(self, request, datapath): _skip_if_no_pymysql() import pymysql + from pymysql.err import Error try: # Try Travis defaults. # 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 Error: pass else: return diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 1718c6beaef55..969ab37e0a942 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -1375,7 +1375,7 @@ def f(): try: df = f() - except: + except Exception: pass assert (df['foo', 'one'] == 0).all() diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index b6c2c65fb6dce..92f82d148f33f 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -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]': @@ -167,11 +167,11 @@ def _coerce_tds(targ, res): else: try: res = res.astype('c16') - except: + except Exception: res = res.astype('f8') try: targ = targ.astype('c16') - except: + except Exception: targ = targ.astype('f8') # there should never be a case where numpy returns an object # but nanops doesn't, so make that an exception diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 51c779c6a97a3..dd458248c5276 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -335,13 +335,13 @@ def check_op(op, name): for op in ops: try: check_op(getattr(operator, op), op) - except: + except (AttributeError, KeyError): pprint_thing("Failing operation: %r" % op) raise if compat.PY3: try: check_op(operator.truediv, 'div') - except: + except (AttributeError, KeyError): pprint_thing("Failing operation: %r" % 'div') raise diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index bd450cdcf8054..1d81d118431d1 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -2660,7 +2660,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