-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG/CLN: Minimize number of ResourceWarnings #38168
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
Conversation
jreback
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! just a small comment
pandas/io/parsers.py
Outdated
| self._reader = parsers.TextReader(self.handles.handle, **kwds) | ||
| try: | ||
| self._reader = parsers.TextReader(self.handles.handle, **kwds) | ||
| except Exception as err: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh here's the issue
try:
.....
finally:
self.handle.close()
should do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want the original exception to raise as is, but of course close if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that first but unfortunately we might need the reader (and the file handles) if we iteratively read in chunks. We can only close the handle in case of an error.
I think a plain raise would be the best solution? It doesn't seem to add anything new to the traceback.
|
thanks @twoertwein |
black pandasgit diff upstream/master -u -- "*.py" | flake8 --diffI think I got all
ResourceWarnings when running:PYTHONWARNINGS=default pytest pandas/tests/io