-
Notifications
You must be signed in to change notification settings - Fork 10
unpin numpy to enable working with numpy version 2 as well #689
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
Changes from all commits
ec1eac2
633434d
fb576dd
161e982
0b0bd8a
31f35dd
9c14555
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
|
|
||
| import h5py | ||
| import yaml | ||
| from numpy import string_ | ||
|
|
||
| TYPE = "_type_" | ||
|
|
||
|
|
@@ -45,7 +44,8 @@ def unpack_dataset(item): | |
|
|
||
| """ | ||
| value = item[()] | ||
| type_id = item.attrs.get(TYPE, string_()).astype(str) | ||
| type_id = item.attrs.get(TYPE, "") | ||
|
|
||
| if type_id == "datetime": | ||
| if hasattr(value, "__iter__"): | ||
| value = [datetime.fromtimestamp(ts) for ts in value] | ||
|
|
@@ -62,7 +62,7 @@ def unpack_dataset(item): | |
| value = tuple(value) | ||
|
|
||
| elif type_id == "str": | ||
| value = string_(value).astype(str) | ||
| value = value.decode("utf-8") if isinstance(value, bytes) else value | ||
|
|
||
| return value | ||
|
|
||
|
|
@@ -181,15 +181,16 @@ def pack_dataset(hdfobject, key, value): | |
| attr_data = None | ||
|
|
||
| if attr_data: | ||
| ds.attrs.create(name=TYPE, data=string_(attr_data)) | ||
| ds.attrs.create(name=TYPE, data=attr_data.encode("utf-8")) | ||
|
|
||
| except (TypeError, ValueError): | ||
| # Obviously the data was not serializable. To give it | ||
| # a last try; serialize it to yaml | ||
| # and save it to the hdf file: | ||
| ds = hdfobject.create_dataset(name=key, data=string_(yaml.safe_dump(value))) | ||
|
|
||
| ds.attrs.create(name=TYPE, data=string_("yaml")) | ||
| ds = hdfobject.create_dataset( | ||
| name=key, data=yaml.safe_dump(value).encode("utf-8") | ||
| ) | ||
| ds.attrs.create(name=TYPE, data=b"yaml") | ||
| # if this fails again, restructure your data! | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "restructure your data" should be emitted as a message if it fails again
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I did not change the code. Could be made more robust in the future, but not here. |
||
|
|
||
|
|
||
|
|
||
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.
If we wish to support arbitrary string payload then we need to think about what happens when decode() raises a UnicodeError
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.
Its okay to address this via #705
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.
Please note that the whole
hdfdict.pyis just a copy of https://github.com/SiggiGue/hdfdict/blob/master/hdfdict/hdfdict.py (which we had to copy because we wanted to have a stable version and there was no release management on the existing tool at the time). I only made changes here that are related to upgrading tonumpy>2, so any decoding problems we had before will be the same. We can discuss this elsewhere later.