Skip to content

Commit d4a6b8c

Browse files
jbrockmendelproost
authored andcommitted
CLN: fix bare excepts on close (pandas-dev#28343)
1 parent 1f91636 commit d4a6b8c

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

pandas/_libs/parsers.pyx

+2-4
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,8 @@ cdef class TextReader:
567567
# we need to properly close an open derived
568568
# filehandle here, e.g. and UTFRecoder
569569
if self.handle is not None:
570-
try:
571-
self.handle.close()
572-
except:
573-
pass
570+
self.handle.close()
571+
574572
# also preemptively free all allocated memory
575573
parser_free(self.parser)
576574
if self.true_set:

pandas/io/common.py

+3
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ def readline(self) -> bytes:
600600
def next(self) -> bytes:
601601
return next(self.reader).encode("utf-8")
602602

603+
def close(self):
604+
self.reader.close()
605+
603606

604607
# Keeping these class for now because it provides a necessary convenience
605608
# for "dropping" the "encoding" argument from our I/O arguments when

pandas/io/json/_json.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,8 @@ def read_json(
587587

588588
result = json_reader.read()
589589
if should_close:
590-
try:
591-
filepath_or_buffer.close()
592-
except: # noqa: flake8
593-
pass
590+
filepath_or_buffer.close()
591+
594592
return result
595593

596594

pandas/io/parquet.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ def read(self, path, columns=None, **kwargs):
125125
path, columns=columns, **kwargs
126126
).to_pandas()
127127
if should_close:
128-
try:
129-
path.close()
130-
except: # noqa: flake8
131-
pass
128+
path.close()
132129

133130
return result
134131

0 commit comments

Comments
 (0)