Skip to content

CLN GH22875 Replace bare excepts by explicit excepts in pandas/io/ #22916

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
wants to merge 6 commits into from
Closed

CLN GH22875 Replace bare excepts by explicit excepts in pandas/io/ #22916

wants to merge 6 commits into from

Conversation

JustinZhengBC
Copy link
Contributor

I removed the except block in pandas/io/pickle.py:172:13 because the only difference between the try block and the except block was one parameter in the call to pc.load, and the parameter that was changing didn't look like it was being used by pc.load.

Original block:

try:
    return read_wrapper(
        lambda f: pc.load(f, encoding=encoding, compat=False))
# compat pickle
except:
    return read_wrapper(
        lambda f: pc.load(f, encoding=encoding, compat=True))

The function it was calling (in pandas/compat/pickle_compat.py):

def load(fh, encoding=None, compat=False, is_verbose=False):
    """load a pickle, with a provided encoding

    if compat is True:
       fake the old class hierarchy
       if it works, then return the new type objects

    Parameters
    ----------
    fh: a filelike object
    encoding: an optional encoding
    compat: provide Series compatibility mode, boolean, default False
    is_verbose: show exception output
    """

    try:
        fh.seek(0)
        if encoding is not None:
            up = Unpickler(fh, encoding=encoding)
        else:
            up = Unpickler(fh)
        up.is_verbose = is_verbose

        return up.load()
    except:
        raise

@pep8speaks
Copy link

Hello @JustinZhengBC! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Oct 1, 2018

Codecov Report

Merging #22916 into master will not change coverage.
The diff coverage is 31.57%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22916   +/-   ##
=======================================
  Coverage   92.18%   92.18%           
=======================================
  Files         169      169           
  Lines       50830    50830           
=======================================
  Hits        46860    46860           
  Misses       3970     3970
Flag Coverage Δ
#multiple 90.6% <31.57%> (ø) ⬆️
#single 42.37% <5.26%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/io/clipboards.py 100% <ø> (ø) ⬆️
pandas/io/formats/terminal.py 21.25% <0%> (ø) ⬆️
pandas/io/packers.py 88.04% <0%> (ø) ⬆️
pandas/io/sas/sas_xport.py 90.23% <0%> (ø) ⬆️
pandas/io/sas/sasreader.py 86.2% <0%> (ø) ⬆️
pandas/io/parsers.py 95.6% <50%> (ø) ⬆️
pandas/io/formats/console.py 75.75% <75%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f1b842...90cfe17. Read the comment docs.

@datapythonista datapythonista added Error Reporting Incorrect or improved errors from pandas CI Continuous Integration Code Style Code style, linting, code_checks labels Oct 1, 2018
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, if you can just delete those unnecessary comments

@jreback ?

Thanks @JustinZhengBC

@@ -459,7 +459,7 @@ def _read(filepath_or_buffer, kwds):
if should_close:
try:
filepath_or_buffer.close()
except: # noqa: flake8
except ValueError: # noqa: flake8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the noqa shouldn't be necessary anymore

@@ -194,7 +194,7 @@ def read(fh):
if should_close:
try:
path_or_buf.close()
except: # noqa: flake8
except IOError: # noqa: flake8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the noqa shouldn't be necessary anymore

@datapythonista
Copy link
Member

@JustinZhengBC any reason to close this PR? I think it was ready to be merged.

@JustinZhengBC
Copy link
Contributor Author

I was trying to get Travis to rebuild by closing and reopening but it turns out that doesn’t work if I previously deleted my fork (which I did after accidentally pushing to master). I have resubmitted it as referenced above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Code Style Code style, linting, code_checks Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace bare excepts by explicit excepts in pandas/io/
3 participants