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
ENH group attribute access for HDFStore #7334
Conversation
this was originally discussed in #2485. Given that I show this in the cookbook, might be a nice feature. Couple of issues:
|
@cpcloud I know you use HDF5 a bit....what do you think about this feature? |
👍 on this. @wabu can u give an usage example of reading attributes in the top of the PR? -1 on in my use cases i have metadata that i don't want to store as an array and it may apply to all the frames in a particular group. one ubiquitous example is sampling rate, which may apply to multiple frames but i don't want to store as a single element series (which is what i do now). as for appending data, seems like should overwrite if new values for attributes are provided and keep whatever's there already. similar to how |
when appending, attribute values are overwritten, but older keys stay:
so I'll document the behavior? |
hmm, maybe better than putting this on the append call, how about a pair of |
API like store.get_attrs('nested/group', ['a', 'b'])
store.set_attrs('nested/group', dict(a=1, b=2)) ? |
yep, though could also have a |
|
@wabu i think that is a reasonable interface. You will restrict the keys to only non-space keys e.g. you are ONLY going to return the attrs IF also prob then need to add to |
Here's my impl. Still have to update docs n' stuff, but wanted to make get a first feedback. I updated the first comment to give an overview of the changes. I'm using
|
@@ -65,6 +66,7 @@ def _ensure_encoding(encoding): | |||
|
|||
Term = Expr | |||
|
|||
_raise_attribute = object() |
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.
tthis is very odd to do this? what is the purpose?
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 use it as a distinguishable default value. If another default value is give, it will be used when an attribute is missing, if no default value is given, an error should be raise. A simple return_attrs(..., default=None)
can't be used as the code can't decide if it should return None as default or raise as default is not given.
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.
do you have any better ideas how to handle this? It would also be used for get_attrs
. One could also have a look at *args
and **kwargs
, but I think ugly as well.
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.
it seems that get_attrs is basically get so on non-existence of an attribute just return default - I think that's fine
his api is getting to be way too bloated I would revert back to only having a |
yes, totally with you on this. where should |
I think it would be ok to directly import, e.g. |
@wabu ? |
- HDFStore.set_attrs to store attribute of a group - HDFStore.get_attrs access to attributes - toplevel set_attrs/get_attrs with hdf5-file passed as string - attrs dict for to_hdf, put, append to store attributes
ok, did the set_attrs, get_attrs thing, also let the attrs=dict() for the write functions (to_hdf, put, append), so one is encouraged to put meta data with the data and it did not complicate the code, but I can remove this also. |
sets attributes of a node | ||
|
||
Note that the size of the metastore for a group inside a hdf5 file is | ||
limited and already used for internal metadata, so be carefull about |
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.
careful
@wabu status on this? |
@wabu status? |
closing for now. @wabu if you'd like to update, happy to reopen. |
Summary:
store.set_attrs(key, **attrs)
to set attributes of a groupstore.get_attrs(key, attrs, default)
returns namedtuple with values from a groups attributes or single attribute directly if attrs is specified as a single stringto_hdf
,put
andappend
have optionalattrs=dict(...)
argument to update attributes when storing an objectExamples: