Skip to content

CLN: fix bare excepts on close #28343

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

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,8 @@ cdef class TextReader:
# we need to properly close an open derived
# filehandle here, e.g. and UTFRecoder
if self.handle is not None:
try:
self.handle.close()
except:
pass
self.handle.close()

# also preemptively free all allocated memory
parser_free(self.parser)
if self.true_set:
Expand Down
3 changes: 3 additions & 0 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ def readline(self) -> bytes:
def next(self) -> bytes:
return next(self.reader).encode("utf-8")

def close(self):
self.reader.close()


# Keeping these class for now because it provides a necessary convenience
# for "dropping" the "encoding" argument from our I/O arguments when
Expand Down
6 changes: 2 additions & 4 deletions pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,8 @@ def read_json(

result = json_reader.read()
if should_close:
try:
filepath_or_buffer.close()
except: # noqa: flake8
pass
filepath_or_buffer.close()

return result


Expand Down
5 changes: 1 addition & 4 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ def read(self, path, columns=None, **kwargs):
path, columns=columns, **kwargs
).to_pandas()
if should_close:
try:
path.close()
except: # noqa: flake8
pass
path.close()

return result

Expand Down