TypeError: Object dtype dtype('O') has no native HDF5 equivalent

2,829 views
Skip to first unread message

Xuesong Yang

unread,
Jan 7, 2016, 7:24:37 PM1/7/16
to h5py
I am a newbie using h5py. I would like to write a list (or ndarray) into a hdf5 file. Each element in the list (ndarray) has different dimensions with each other. However, it always failed everty time I tried. I appreciate it if I could gain some help here. Thanks

Test code is shown as follows:

  1 import h5py
  2 
  3 test_f5 = [[[1, 2],[3, 4]], [[5, 6], [7, 8], [9, 10]]]
  4 
  5 f = h5py.File('test.hdf5', 'w')
  6 dset = f.create_dataset('test_f5', data=test_f5, compression='gzip', compression_opts=9)
  7 f.close()

After run this code, it prompts errors:

Traceback (most recent call last):
  File "test_h5py.py", line 6, in <module>
    dset = f.create_dataset('test_f5', data=test_f5, compression='gzip', compression_opts=9)
  File "/work/miniconda2/lib/python2.7/site-packages/h5py/_hl/group.py", line 103, in create_dataset
    dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)
  File "/work/miniconda2/lib/python2.7/site-packages/h5py/_hl/dataset.py", line 87, in make_new_dset
    tid = h5t.py_create(dtype, logical=1)
  File "h5py/h5t.pyx", line 1448, in h5py.h5t.py_create (/home/ilan/minonda/conda-bld/work/h5py/h5t.c:16162)
  File "h5py/h5t.pyx", line 1468, in h5py.h5t.py_create (/home/ilan/minonda/conda-bld/work/h5py/h5t.c:15993)
  File "h5py/h5t.pyx", line 1523, in h5py.h5t.py_create (/home/ilan/minonda/conda-bld/work/h5py/h5t.c:15895)
TypeError: Object dtype dtype('O') has no native HDF5 equivalent

As suggested recently, I applied `h5py.special_dtype()` to fix that:

  1 import h5py
  2 import numpy as np
  3 
  4 test_f5 = [[[1, 2],[3, 4]], [[5, 6], [7, 8], [9, 10]]]
  5 
  6 f = h5py.File('test.hdf5', 'w')
  7 spec_dtype = h5py.special_dtype(vlen=np.dtype('float64'))
  8 dset = f.create_dataset('test_f5', data=test_f5, dtype=spec_dtype, compression='gzip', compression_opts=9)
  9 f.close()

Then another error is prompted:

Traceback (most recent call last):
  File "test_h5py.py", line 8, in <module>
    dset = f.create_dataset('test_f5', data=test_f5, dtype=spec_dtype, compression='gzip', compression_opts=9)
  File "/work/miniconda2/lib/python2.7/site-packages/h5py/_hl/group.py", line 103, in create_dataset
    dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)
  File "/work/miniconda2/lib/python2.7/site-packages/h5py/_hl/dataset.py", line 126, in make_new_dset
    dset_id.write(h5s.ALL, h5s.ALL, data)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/home/ilan/minonda/conda-bld/work/h5py/_objects.c:2579)
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/home/ilan/minonda/conda-bld/work/h5py/_objects.c:2538)
  File "h5py/h5d.pyx", line 217, in h5py.h5d.DatasetID.write (/home/ilan/minonda/conda-bld/work/h5py/h5d.c:3421)
  File "h5py/_proxy.pyx", line 163, in h5py._proxy.dset_rw (/home/ilan/minonda/conda-bld/work/h5py/_proxy.c:2102)
  File "h5py/defs.pyx", line 2800, in h5py.defs.H5Tconvert (/home/ilan/minonda/conda-bld/work/h5py/defs.c:29440)
  File "h5py/_conv.pyx", line 712, in h5py._conv.ndarray2vlen (/home/ilan/minonda/conda-bld/work/h5py/_conv.c:6176)
AttributeError: 'list' object has no attribute 'dtype'








Reply all
Reply to author
Forward
0 new messages