From 27d9c16c0b5931efa69af522cf943cc22e270edd Mon Sep 17 00:00:00 2001 From: Anudeep Tubati Date: Sun, 30 Sep 2018 14:09:37 +0530 Subject: [PATCH 1/6] Added explicit exceptions to 'compat/pickle_compat.py' and 'util/_validators.py' --- pandas/compat/pickle_compat.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index c1a9a9fc1ed13..713a5b1120beb 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -33,7 +33,7 @@ def load_reduce(self): cls = args[0] stack[-1] = object.__new__(cls) return - except: + except TypeError: pass # try to re-encode the arguments @@ -44,7 +44,7 @@ def load_reduce(self): try: stack[-1] = func(*args) return - except: + except TypeError: pass # unknown exception, re-raise @@ -182,7 +182,7 @@ def load_newobj_ex(self): try: Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex -except: +except (AttributeError, KeyError): pass @@ -210,5 +210,5 @@ def load(fh, encoding=None, compat=False, is_verbose=False): up.is_verbose = is_verbose return up.load() - except: + except (ValueError, TypeError): raise From 9809410ea3b78ad375e2880ea263d4ba745a7a29 Mon Sep 17 00:00:00 2001 From: Anudeep Tubati <40491005+NeuralFlux@users.noreply.github.com> Date: Sun, 30 Sep 2018 14:12:34 +0530 Subject: [PATCH 2/6] Added explicit exceptions to 'util/_validators.py' --- pandas/util/_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index a96563051e7de..e51e0c88e5b95 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -59,7 +59,7 @@ def _check_for_default_values(fname, arg_val_dict, compat_args): # could not compare them directly, so try comparison # using the 'is' operator - except: + except ValueError: match = (arg_val_dict[key] is compat_args[key]) if not match: From 9042d428985595193ad72e094f5e9f6dad96eb3b Mon Sep 17 00:00:00 2001 From: Anudeep Tubati <40491005+NeuralFlux@users.noreply.github.com> Date: Sun, 30 Sep 2018 14:13:55 +0530 Subject: [PATCH 3/6] Added explicit exceptions to '_print_versions.py' --- pandas/util/_print_versions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/util/_print_versions.py b/pandas/util/_print_versions.py index 5600834f3b615..4a0ea0541a9f0 100644 --- a/pandas/util/_print_versions.py +++ b/pandas/util/_print_versions.py @@ -21,7 +21,7 @@ def get_sys_info(): stdout=subprocess.PIPE, stderr=subprocess.PIPE) so, serr = pipe.communicate() - except: + except (OSError, ValueError): pass else: if pipe.returncode == 0: @@ -50,7 +50,7 @@ def get_sys_info(): ("LANG", "{lang}".format(lang=os.environ.get('LANG', "None"))), ("LOCALE", '.'.join(map(str, locale.getlocale()))), ]) - except: + except (KeyError, ValueError): pass return blob @@ -108,7 +108,7 @@ def show_versions(as_json=False): mod = importlib.import_module(modname) ver = ver_f(mod) deps_blob.append((modname, ver)) - except: + except ModuleNotFoundError: deps_blob.append((modname, None)) if (as_json): From 07ec0540d5dfac6258cebe97643c8affb0f51106 Mon Sep 17 00:00:00 2001 From: Anudeep Tubati <40491005+NeuralFlux@users.noreply.github.com> Date: Sun, 30 Sep 2018 14:16:23 +0530 Subject: [PATCH 4/6] Added explicit exceptions to holiday.py --- pandas/tseries/holiday.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index b9c89c4e314f9..eab3381d496d6 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -294,7 +294,7 @@ def _apply_rule(self, dates): def register(cls): try: name = cls.name - except: + except AttributeError: name = cls.__name__ holiday_calendars[name] = cls @@ -426,7 +426,7 @@ def merge_class(base, other): """ try: other = other.rules - except: + except AttributeError: pass if not isinstance(other, list): @@ -435,7 +435,7 @@ def merge_class(base, other): try: base = base.rules - except: + except AttributeError: pass if not isinstance(base, list): From 67645dea95355889610e455a7adef01da359cb0f Mon Sep 17 00:00:00 2001 From: Anudeep Tubati <40491005+NeuralFlux@users.noreply.github.com> Date: Sun, 30 Sep 2018 14:26:26 +0530 Subject: [PATCH 5/6] PEP8 compatibility issues resolved --- pandas/tseries/holiday.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index eab3381d496d6..0497a827e2e1b 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -294,7 +294,7 @@ def _apply_rule(self, dates): def register(cls): try: name = cls.name - except AttributeError: + except AttributeError: name = cls.__name__ holiday_calendars[name] = cls @@ -426,7 +426,7 @@ def merge_class(base, other): """ try: other = other.rules - except AttributeError: + except AttributeError: pass if not isinstance(other, list): @@ -435,7 +435,7 @@ def merge_class(base, other): try: base = base.rules - except AttributeError: + except AttributeError: pass if not isinstance(base, list): From 87ea4d83e9aa2eb701adde0f1a267145d7e1c83e Mon Sep 17 00:00:00 2001 From: Anudeep Tubati <40491005+NeuralFlux@users.noreply.github.com> Date: Sun, 30 Sep 2018 22:40:52 +0530 Subject: [PATCH 6/6] Made compatible with Py2.7 Changed ModuleNotFoundError to ImportError --- pandas/util/_print_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/_print_versions.py b/pandas/util/_print_versions.py index 4a0ea0541a9f0..03fc82a3acef5 100644 --- a/pandas/util/_print_versions.py +++ b/pandas/util/_print_versions.py @@ -108,7 +108,7 @@ def show_versions(as_json=False): mod = importlib.import_module(modname) ver = ver_f(mod) deps_blob.append((modname, ver)) - except ModuleNotFoundError: + except ImportError: deps_blob.append((modname, None)) if (as_json):