-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: close hdf store on any error #28429
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
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.
Can you add a test and a whatsnew for v1.0.0 when you get the chance?
Sure, I will do that in the next days |
cc7bbd2
to
f96d66b
Compare
I've just re-requested your review for a first version of the PR. |
f96d66b
to
3160972
Compare
CI is failing… It looks like some exceptions are exceptions are expected not to close the HDF store... Should we explicitly whitelist these exceptions or should we do the opposite, i.e. list all exceptions we should close the store on? In my specific case, I expected the store to be closed on |
Which tests are failing because of that? Something like I also would have expected an exception to close an auto-opened store. |
The failing tests are:
I didn't have the time to check for now, probably something going on with the iteration protocol. I will try to do that soon. |
we would want to close the store on all exceptions, likely this is an oversite. |
try: | ||
HDFStore(path, mode="w") | ||
except ValueError as exc: | ||
pytest.fail( |
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.
you don't need to catch something that you are expecting to pass
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.
Thanks @jreback for the feedback. I'm not exactly sure about what you meant but if you suggest to remove the except ValueError
, that was done on purpose in order to fail (F
) rather than to output an error (E
).
@jreback ok, thanks! Should I go and fix the other tests accordingly then? |
I think the tests can be updated where needed. One question: if a user does something like store = pd.HDFStore(...)
store.<something that causes an exception> then will the |
this PR is slightly orthogonal to #28700 so if you want to rebase after we merge that would be great. |
@adimascio can you merge master on this? |
3160972
to
2f2d8a9
Compare
@WillAyd @jreback I've just rebased on master. I will try to fix the tests as discussed earlier this week-end! |
@adimascio can you fix the merge conflict on the whatsnew and see if you can get this green? |
1 similar comment
@adimascio can you fix the merge conflict on the whatsnew and see if you can get this green? |
@adimascio can you fix the merge conflict and see if you can get the CI passing |
In `read_hdf`, if the `store.select()` call throws either a `ValueError`, a `TypeError` or a `KeyError` then the store is closed. However, if any other exception is thrown (e.g. an `AssertionError` if there are gaps in blocks ref_loc) , the store is not closed and some client code could end up trying to reopen the store and hit an error like: `the file XXX is already opened. Please close it before reopening in write mode`. Furthermore, the exception is re-raised in all cases. This commit just closes store in all cases. Closes pandas-dev#28430
2f2d8a9
to
3dcf7f0
Compare
I've just push-forced to fix the conflicts. I'll try to fix the CI soon. |
@adimascio pls merge master and see if you can get passing |
Closing as CI is red and I think this has gone stale, but ping if you’d like to pick this back up and can reopen |
NOTE: I'm opening the PR mainly to open a discussion about the current behaviour. If this is intended, please tell me. If not and you need me to write some tests, I'll do it :)
In
read_hdf
, if thestore.select()
call throws either aValueError
, aTypeError
or aKeyError
then the store is closed.However, if any other exception is thrown (e.g. an
AssertionError
ifthere are gaps in blocks ref_loc) , the store is not closed and some
client code could end up trying to reopen the store and hit an
error like:
the file XXX is already opened. Please close it before reopening in write mode
. Furthermore, the exception is re-raised in allcases.
This commit just catches any exception.
Closes #28430
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff