-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: enable support for iterator with read_hdf in HDFStore (GH3937) #3949
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
DOC: update v0.11.1.rst
ENH: enable support for iterator with read_hdf in HDFStore (GH3937)
@jreback I had a slightly different idea about how to do this that I actually think simplifies everything (turn store into a context manager itself). That lets you do something like: with get_store(path) as store:
store['foo'] = bar Check it out here: https://github.com/jtratner/pandas/tree/change-store-to-contextmanager-type You could actually remove |
aside from the ability to directly use |
Major difference is that it lets you use store = get_store('asdfa.h5')
# do some things
with store:
# do some stuff where it's important to close it up Whereas right now, you have to use It also would let you use the iterator in a with statement directly - I was On Wed, Jun 19, 2013 at 7:34 AM, jreback [email protected] wrote:
|
I think this will close it always though....e.g
as an aside, prob should add ? |
I don't think the code you have there will work as written. Get store returns a context manager not a HDFStore. You only get the store if you call |
Another side note would it make more sense to have open raise an error or warning instead of raw input? Causes the test suite to unexpectedly hang when you try to use it. Maybe instead the check could be (pseudocode) if is open and mode==w:
if not force: raise some exception Because I think that the larger issue is that you can call open repeatedly and have it overwrite itself in w mode |
my example was using your code, the question is how does the context manager know not to the whole bizness of |
It doesn't, if you use store as a context manager, the expectation should be that it closes on leaving the with context, just like other file objects. Only table iterator needs to know about auto closing. |
ok then.....if you want to do a PR, ok....only thing is need a test for it (also pls add
|
And actually given the way that you can reopen it, you could repeatedly use it as a context manager and have it open and close each time, so that it's only open when you are specifically choosing to use it (eg if it's important for more than one program to access it) . If we could get rid of 'w' the mode it'd be a lot better, because then it's never problematic to reopen. (no chance of overwriting anything). |
fyi, I always open in |
@jreback can we deprecate support for 'w' mode? |
i think u need it |
closes #3937
DOC: update v0.11.1.rst