Skip to content

Commit 4226d74

Browse files
NeuralFluxjreback
authored andcommitted
STYLE: Added explicit exceptions (pandas-dev#22907)
1 parent 2f1b842 commit 4226d74

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

pandas/compat/pickle_compat.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def load_reduce(self):
3333
cls = args[0]
3434
stack[-1] = object.__new__(cls)
3535
return
36-
except:
36+
except TypeError:
3737
pass
3838

3939
# try to re-encode the arguments
@@ -44,7 +44,7 @@ def load_reduce(self):
4444
try:
4545
stack[-1] = func(*args)
4646
return
47-
except:
47+
except TypeError:
4848
pass
4949

5050
# unknown exception, re-raise
@@ -182,7 +182,7 @@ def load_newobj_ex(self):
182182

183183
try:
184184
Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex
185-
except:
185+
except (AttributeError, KeyError):
186186
pass
187187

188188

@@ -210,5 +210,5 @@ def load(fh, encoding=None, compat=False, is_verbose=False):
210210
up.is_verbose = is_verbose
211211

212212
return up.load()
213-
except:
213+
except (ValueError, TypeError):
214214
raise

pandas/tseries/holiday.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def _apply_rule(self, dates):
294294
def register(cls):
295295
try:
296296
name = cls.name
297-
except:
297+
except AttributeError:
298298
name = cls.__name__
299299
holiday_calendars[name] = cls
300300

@@ -426,7 +426,7 @@ def merge_class(base, other):
426426
"""
427427
try:
428428
other = other.rules
429-
except:
429+
except AttributeError:
430430
pass
431431

432432
if not isinstance(other, list):
@@ -435,7 +435,7 @@ def merge_class(base, other):
435435

436436
try:
437437
base = base.rules
438-
except:
438+
except AttributeError:
439439
pass
440440

441441
if not isinstance(base, list):

pandas/util/_print_versions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_sys_info():
2121
stdout=subprocess.PIPE,
2222
stderr=subprocess.PIPE)
2323
so, serr = pipe.communicate()
24-
except:
24+
except (OSError, ValueError):
2525
pass
2626
else:
2727
if pipe.returncode == 0:
@@ -50,7 +50,7 @@ def get_sys_info():
5050
("LANG", "{lang}".format(lang=os.environ.get('LANG', "None"))),
5151
("LOCALE", '.'.join(map(str, locale.getlocale()))),
5252
])
53-
except:
53+
except (KeyError, ValueError):
5454
pass
5555

5656
return blob
@@ -108,7 +108,7 @@ def show_versions(as_json=False):
108108
mod = importlib.import_module(modname)
109109
ver = ver_f(mod)
110110
deps_blob.append((modname, ver))
111-
except:
111+
except ImportError:
112112
deps_blob.append((modname, None))
113113

114114
if (as_json):

pandas/util/_validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _check_for_default_values(fname, arg_val_dict, compat_args):
5959

6060
# could not compare them directly, so try comparison
6161
# using the 'is' operator
62-
except:
62+
except ValueError:
6363
match = (arg_val_dict[key] is compat_args[key])
6464

6565
if not match:

0 commit comments

Comments
 (0)