-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
(superseeds #18419, same task for different files: #22872, #22873, #22874, #22875)
In several parts of the code, we have bare excepts in the form of:
try:
my_value = my_dict[my_key]
except: # we are capturing all the exceptions, when we want to capture only KeyError
my_value = NoneThis is a bad practice, and we want to avoid having this in the code. What we want instead is:
try:
my_value = my_dict[my_key]
except KeyError:
my_value = NoneOf course in every case, the exception can be different (not always KeyError), and some research is needed to see which is the right exception (or exceptions, it can be a tuple) that needs to be captured. In some cases, every exception needs to be captured and we'll use except Exception:, but this should be avoided unless we really need to capture all exceptions.
This issue is to fix all the bare excepts in testing files pandas/tests/. At the moment they are (note that the list can change as code evolves):
pandas/compat/pickle_compat.py:36:13: E722 do not use bare except'
pandas/compat/pickle_compat.py:47:13: E722 do not use bare except'
pandas/compat/pickle_compat.py:185:1: E722 do not use bare except'
pandas/compat/pickle_compat.py:213:5: E722 do not use bare except'
pandas/tseries/holiday.py:297:5: E722 do not use bare except'
pandas/tseries/holiday.py:429:9: E722 do not use bare except'
pandas/tseries/holiday.py:438:9: E722 do not use bare except'
pandas/util/_print_versions.py:24:9: E722 do not use bare except'
pandas/util/_print_versions.py:53:5: E722 do not use bare except'
pandas/util/_print_versions.py:111:9: E722 do not use bare except'
pandas/util/_validators.py:62:9: E722 do not use bare except'
An updated list can be obtained by running: flake8 --select=E722 --config=none --exclude=pandas/tests,pandas/io,pandas/core pandas