Skip to content

Replace bare excepts by explicit excepts in pandas/io/pytables #22874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
datapythonista opened this issue Sep 28, 2018 · 3 comments · Fixed by #22919
Closed

Replace bare excepts by explicit excepts in pandas/io/pytables #22874

datapythonista opened this issue Sep 28, 2018 · 3 comments · Fixed by #22919
Labels
CI Continuous Integration good first issue
Milestone

Comments

@datapythonista
Copy link
Member

datapythonista commented Sep 28, 2018

(superseeds #18419, same task for different files: #22872, #22873, #22875, #22877)

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 = None

This 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 = None

Of 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/io/pytables.py:261:9: E722 do not use bare except'
pandas/io/pytables.py:398:5: E722 do not use bare except'
pandas/io/pytables.py:402:9: E722 do not use bare except'
pandas/io/pytables.py:520:9: E722 do not use bare except'
pandas/io/pytables.py:678:17: E722 do not use bare except'
pandas/io/pytables.py:1164:9: E722 do not use bare except'
pandas/io/pytables.py:1273:9: E722 do not use bare except'
pandas/io/pytables.py:1310:17: E722 do not use bare except'
pandas/io/pytables.py:1321:13: E722 do not use bare except'
pandas/io/pytables.py:1357:17: E722 do not use bare except'
pandas/io/pytables.py:1362:9: E722 do not use bare except'
pandas/io/pytables.py:1627:9: E722 do not use bare except'
pandas/io/pytables.py:1659:9: E722 do not use bare except'
pandas/io/pytables.py:1872:9: E722 do not use bare except'
pandas/io/pytables.py:2235:17: E722 do not use bare except'
pandas/io/pytables.py:2328:9: E722 do not use bare except'
pandas/io/pytables.py:2772:17: E722 do not use bare except'
pandas/io/pytables.py:2846:9: E722 do not use bare except'
pandas/io/pytables.py:2964:9: E722 do not use bare except'
pandas/io/pytables.py:3498:13: E722 do not use bare except'
pandas/io/pytables.py:3617:17: E722 do not use bare except'
pandas/io/pytables.py:3645:17: E722 do not use bare except'
pandas/io/pytables.py:4463:5: E722 do not use bare except'
pandas/io/pytables.py:4785:13: E722 do not use bare except'

An updated list can be obtained by running: flake8 --select=E722 --config=none pandas/io/pytables/

@jreback
Copy link
Contributor

jreback commented Sep 28, 2018

can u reference the other issue

@datapythonista
Copy link
Member Author

yes, I'm creating various issues, when I finish I'll cross-reference all them

@pambot
Copy link
Contributor

pambot commented Sep 30, 2018

I'll do this one too while the other one is in review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants