現在、h5py は時間タイプ ( FAQ、Issue )をサポートしていません。
NumPy の datetime64 は 8 バイトの長さです。したがって、回避策として'<i8'
、int を hdf5 ファイルに格納するようにデータを表示し、np.datetime64
取得時にそれを表示することができます。
import numpy as np
import h5py
arr = np.linspace(0, 10000, 4).astype('<i8').view('<M8[D]').reshape((2,2))
print(arr)
# [['1970-01-01' '1979-02-16']
# ['1988-04-02' '1997-05-19']]
with h5py.File('/tmp/out.h5', "w") as f:
dset = f.create_dataset('data', (2, 2), '<i8')
dset[:,:] = arr.view('<i8')
with h5py.File('/tmp/out.h5', "r") as f:
dset = f.get('data')
print(dset.value.view('<M8[D]'))
# [['1970-01-01' '1979-02-16']
# ['1988-04-02' '1997-05-19']]