From 2c59bee16b21863c40039a25f05025be647b7bf1 Mon Sep 17 00:00:00 2001 From: matan Date: Sat, 29 Sep 2018 18:32:57 +0300 Subject: [PATCH 1/3] Better style, More specific exceptions to capture --- asv_bench/benchmarks/algorithms.py | 2 +- asv_bench/benchmarks/join_merge.py | 2 +- asv_bench/benchmarks/pandas_vb_common.py | 4 ++-- asv_bench/benchmarks/stat_ops.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/asv_bench/benchmarks/algorithms.py b/asv_bench/benchmarks/algorithms.py index cccd38ef11251..fc34440ece2ed 100644 --- a/asv_bench/benchmarks/algorithms.py +++ b/asv_bench/benchmarks/algorithms.py @@ -9,7 +9,7 @@ try: hashing = import_module(imp) break - except: + except (ImportError, TypeError, ValueError): pass from .pandas_vb_common import setup # noqa diff --git a/asv_bench/benchmarks/join_merge.py b/asv_bench/benchmarks/join_merge.py index de0a3b33da147..7487a0d8489b7 100644 --- a/asv_bench/benchmarks/join_merge.py +++ b/asv_bench/benchmarks/join_merge.py @@ -29,7 +29,7 @@ def setup(self): try: with warnings.catch_warnings(record=True): self.mdf1.consolidate(inplace=True) - except: + except (AttributeError, TypeError): pass self.mdf2 = self.mdf1.copy() self.mdf2.index = self.df2.index diff --git a/asv_bench/benchmarks/pandas_vb_common.py b/asv_bench/benchmarks/pandas_vb_common.py index e255cd94f265b..0a28af99b737a 100644 --- a/asv_bench/benchmarks/pandas_vb_common.py +++ b/asv_bench/benchmarks/pandas_vb_common.py @@ -9,7 +9,7 @@ try: lib = import_module(imp) break - except: + except (ImportError, TypeError, ValueError): pass numeric_dtypes = [np.int64, np.int32, np.uint32, np.uint64, np.float32, @@ -34,7 +34,7 @@ def remove(self, f): """Remove created files""" try: os.remove(f) - except: + except OSError: # On Windows, attempting to remove a file that is in use # causes an exception to be raised pass diff --git a/asv_bench/benchmarks/stat_ops.py b/asv_bench/benchmarks/stat_ops.py index c447c78d0d070..ecfcb27806f54 100644 --- a/asv_bench/benchmarks/stat_ops.py +++ b/asv_bench/benchmarks/stat_ops.py @@ -18,7 +18,7 @@ def setup(self, op, dtype, axis, use_bottleneck): df = pd.DataFrame(np.random.randn(100000, 4)).astype(dtype) try: pd.options.compute.use_bottleneck = use_bottleneck - except: + except TypeError: from pandas.core import nanops nanops._USE_BOTTLENECK = use_bottleneck self.df_func = getattr(df, op) @@ -56,7 +56,7 @@ def setup(self, op, dtype, use_bottleneck): s = pd.Series(np.random.randn(100000)).astype(dtype) try: pd.options.compute.use_bottleneck = use_bottleneck - except: + except TypeError: from pandas.core import nanops nanops._USE_BOTTLENECK = use_bottleneck self.s_func = getattr(s, op) From 3962f916dd97ff4c84b4d9ff0e48d4d26e85c44f Mon Sep 17 00:00:00 2001 From: matan Date: Sat, 29 Sep 2018 18:36:43 +0300 Subject: [PATCH 2/3] Removed unused imports --- asv_bench/benchmarks/io/csv.py | 2 -- asv_bench/benchmarks/pandas_vb_common.py | 1 - asv_bench/benchmarks/timeseries.py | 1 - 3 files changed, 4 deletions(-) diff --git a/asv_bench/benchmarks/io/csv.py b/asv_bench/benchmarks/io/csv.py index 2d4bdc7ae812a..28e1be33dcb74 100644 --- a/asv_bench/benchmarks/io/csv.py +++ b/asv_bench/benchmarks/io/csv.py @@ -1,11 +1,9 @@ import random -import timeit import string import numpy as np import pandas.util.testing as tm from pandas import DataFrame, Categorical, date_range, read_csv -from pandas.compat import PY2 from pandas.compat import cStringIO as StringIO from ..pandas_vb_common import setup, BaseIO # noqa diff --git a/asv_bench/benchmarks/pandas_vb_common.py b/asv_bench/benchmarks/pandas_vb_common.py index 0a28af99b737a..e7b25d567e03b 100644 --- a/asv_bench/benchmarks/pandas_vb_common.py +++ b/asv_bench/benchmarks/pandas_vb_common.py @@ -2,7 +2,6 @@ from importlib import import_module import numpy as np -from pandas import Panel # Compatibility import for lib for imp in ['pandas._libs.lib', 'pandas.lib']: diff --git a/asv_bench/benchmarks/timeseries.py b/asv_bench/benchmarks/timeseries.py index 2c98cc1659519..2557ba7672a0e 100644 --- a/asv_bench/benchmarks/timeseries.py +++ b/asv_bench/benchmarks/timeseries.py @@ -1,4 +1,3 @@ -import warnings from datetime import timedelta import numpy as np From 9b1cfb28591b52956a25cd0494f3b5450290a874 Mon Sep 17 00:00:00 2001 From: matan Date: Sat, 29 Sep 2018 18:38:15 +0300 Subject: [PATCH 3/3] Fixed line length --- asv_bench/benchmarks/io/csv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asv_bench/benchmarks/io/csv.py b/asv_bench/benchmarks/io/csv.py index 28e1be33dcb74..12cb893462b87 100644 --- a/asv_bench/benchmarks/io/csv.py +++ b/asv_bench/benchmarks/io/csv.py @@ -179,8 +179,8 @@ def time_read_csv(self, sep, decimal, float_precision): names=list('abc'), float_precision=float_precision) def time_read_csv_python_engine(self, sep, decimal, float_precision): - read_csv(self.data(self.StringIO_input), sep=sep, header=None, engine='python', - float_precision=None, names=list('abc')) + read_csv(self.data(self.StringIO_input), sep=sep, header=None, + engine='python', float_precision=None, names=list('abc')) class ReadCSVCategorical(BaseIO):