Closed tacaswell closed 9 years ago
For my own knowledge, when would node.attrs[key] = value
fail?
Looks good. Thanks for doing this
Most of h5py works by casting things to numpy and then mapping from numpy -> hdf5's type system. Anything that fails along that path can't be shove in without custom serialization logic. The simplest is a dict:
In [7]: import h5py
In [8]: f = h5py.File(':memory:')
In [9]: f.attrs
Out[9]: <Attributes of HDF5 object at 140225191548680>
In [10]: f.attrs['foo'] = {'a': 1}
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-2a6fb928d0e9> in <module>()
----> 1 f.attrs['foo'] = {'a': 1}
h5py/_objects.pyx in h5py._objects.with_phil.wrapper (-------src-dir-------/h5py/_objects.c:2458)()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper (-------src-dir-------/h5py/_objects.c:2415)()
/home/tcaswell/.virtualenvs/dd_py3k/lib/python3.4/site-packages/h5py/_hl/attrs.py in __setitem__(self, name, value)
85 use the methods create() and modify().
86 """
---> 87 self.create(name, data=value, dtype=base.guess_dtype(value))
88
89 @with_phil
/home/tcaswell/.virtualenvs/dd_py3k/lib/python3.4/site-packages/h5py/_hl/attrs.py in create(self, name, data, shape, dtype)
161 # Make HDF5 datatype and dataspace for the H5A calls
162 if use_htype is None:
--> 163 htype = h5t.py_create(original_dtype, logical=True)
164 htype2 = h5t.py_create(original_dtype) # Must be bit-for-bit representation rather than logical
165 else:
h5py/h5t.pyx in h5py.h5t.py_create (-------src-dir-------/h5py/h5t.c:15483)()
h5py/h5t.pyx in h5py.h5t.py_create (-------src-dir-------/h5py/h5t.c:15314)()
h5py/h5t.pyx in h5py.h5t.py_create (-------src-dir-------/h5py/h5t.c:15232)()
TypeError: Object dtype dtype('O') has no native HDF5 equivalent
but custom objects and unicode strings also fail.
I also view this as a MVP, others are more than welcome to write dialects that output the data formatted how ever they want.
Ah cool, thanks for the clear example