8

I got this error when using a package to read hdf5 files:

dataset.value

Error:

Traceback (most recent call last):
  File "train.py", line 163, in <module>
    train(0, False, args.gpu_list, args.model_path)
  File "train.py", line 76, in train
    dataset = Ani1Dataset(dir_path='/data/ANI-1_release')
  File "/code/ani1dataset.py", line 16, in __init__
    self.parse(dir_path)
  File "/code/ani1dataset.py", line 32, in parse
    for molecule in adl:
  File "/code/pyanitools.py", line 75, in __iter__
    for data in self.h5py_dataset_iterator(self.store):
  File "/code/pyanitools.py", line 71, in h5py_dataset_iterator
    yield from self.h5py_dataset_iterator(item, path)
  File "/code/pyanitools.py", line 60, in h5py_dataset_iterator
    dataset = np.array(item[k].value)
AttributeError: 'Dataset' object has no attribute 'value'
Jacob Stern
  • 3,758
  • 3
  • 32
  • 54
  • In the code above, if `item[k]` references a HDF5 dataset, you can read it into a NumPy array using `dataset = item[k][:]`. Much cleaner. Also, I would not downgrade to h5py 2.9.0 without a compelling reason. It was released 2014. The current h5py release is 3.2 and supports newer HDF5 formats and has many enhancements and error corrections. – kcw78 May 06 '21 at 14:51

3 Answers3

9

The dataset.value attribute was deprecated. Either use:

dataset[()]

or downgrade h5py to use the old syntax:

pip3 install --upgrade pip && pip3 install h5py=='2.9.0'
Jacob Stern
  • 3,758
  • 3
  • 32
  • 54
7

Yes, .value has been deprecated for some time. As mentioned in my comments above, I would not downgrade to h5py 2.9.0 without a compelling reason. It was released in 2014. The current h5py release is 3.2 and supports the latest HDF5 formats and has many enhancements and error corrections.

There are 2 primary ways to access HDF5 data with h5py. Briefly, you can:

  1. Return a h5py dataset object. A dataset object behaves "as-if" it is an array, but does not load the data into memory until needed.
  2. Return a NumPy array. This immediately loads the data into memory.

Complete h5py dataset documentation here:
Examples of each below:

with h5py.File('filename.h5','r') as h5f:
    # return a h5py dataset object:
    my_ds_obj = h5f[ds_name]
    # return a h5py dataset object:
    my_ds_arr = h5f[ds_name][()]

In addition, if you only want to read some of the data, h5py supports most NumPy slicing syntax, including a subset of fancy indexing. h5py fancy indexing doc

kcw78
  • 7,131
  • 3
  • 12
  • 44
2

.value is deprecated.Use h5f['kVals'][()] rather than h5f['kVals'].value

Copied the above code from this link

user3024119
  • 190
  • 1
  • 2
  • 11