telegraphic / hickle

a HDF5-based python pickle replacement
http://telegraphic.github.io/hickle/
Other
485 stars 70 forks source link

Hickle v4+ regression: unyt_array loses units upon loading #147

Closed DBerke closed 3 years ago

DBerke commented 3 years ago

Unyt is a Python package for adding unit information to numbers which uses a unyt_array class derived from NumPy's ndarray, which allows it to transparently 'drop in' to functions that use and take advantage of NumPy's array functionality. In hickle v3.x (specifically 3.4.9, with h5py=2.10.0), saving a unyt_array with hickle and loading it would preserve the unit information attached. In v4.x of hickle (specifically 4.0.3), unit information is erased upon saving, leading to the loaded value having units of "dimensionless".

$ import unyt, hickle, h5py
$ test = [1, 2, 3] * unyt.K
$ print(test)
>>> unyt_array([1, 2, 3], 'K')
$ with h5py.File(temp, mode='w') as f:
    hickle.dump(test, f, path='test')
$ with h5py.File(temp, mode='r') as f:
    reconstructed = hickle.load(f, path='test')
$ print(reconstructed)
>>> unyt_array([1, 2, 3], '(dimensionless)')
1313e commented 3 years ago

This has to do with the way that unyt inherits NumPy arrays. I will have a look at that soon (hopefully tomorrow).

DBerke commented 3 years ago

Looks like it's working now with v4.0.4, thanks for the fix!