Skip to content

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

Merged
merged 1 commit into from
Dec 1, 2020
Merged

BUG/CLN: Minimize number of ResourceWarnings #38168

merged 1 commit into from
Dec 1, 2020

Conversation

twoertwein
Copy link
Member

@twoertwein twoertwein commented Nov 30, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

I think I got all ResourceWarnings when running:
PYTHONWARNINGS=default pytest pandas/tests/io

@twoertwein twoertwein marked this pull request as ready for review November 30, 2020 02:57
Copy link
Contributor

@jreback jreback left a 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

@jreback jreback added this to the 1.2 milestone Nov 30, 2020
@jreback jreback added the IO Data IO issues that don't fit into a more specific label label Nov 30, 2020
self._reader = parsers.TextReader(self.handles.handle, **kwds)
try:
self._reader = parsers.TextReader(self.handles.handle, **kwds)
except Exception as err:
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member Author

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.

@jreback jreback merged commit a5eb94d into pandas-dev:master Dec 1, 2020
@jreback
Copy link
Contributor

jreback commented Dec 1, 2020

thanks @twoertwein

@twoertwein twoertwein deleted the resources branch December 1, 2020 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants