From b78625b6c37026b6d398618a18de44b169605d54 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:45:30 -0700 Subject: [PATCH] Fix scalar dataset with compound dtype for export (#1185) * convert compound dtype to list on read * revert dtype list checks in validator * update CHANGELOG.md --------- Co-authored-by: Ryan Ly --- CHANGELOG.md | 9 +++------ src/hdmf/backends/hdf5/h5tools.py | 4 ++++ src/hdmf/validate/validator.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b72ead1c5..888a3cb70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,6 @@ # HDMF Changelog -## HDMF 3.14.6 (Upcoming) - -### Bug fixes -- Fixed mamba-related error in conda-based GitHub Actions. @rly [#1194](https://github.com/hdmf-dev/hdmf/pull/1194) - -## HDMF 3.14.5 (September 17, 2024) +## HDMF 3.14.5 (Upcoming) ### Enhancements - Added support for overriding backend configurations of `h5py.Dataset` objects in `Container.set_data_io`. @pauladkisson [#1172](https://github.com/hdmf-dev/hdmf/pull/1172) @@ -13,6 +8,8 @@ ### Bug fixes - Fixed bug in writing of string arrays to an HDF5 file that were read from an HDF5 file that was introduced in 3.14.4. @rly @stephprince [#1189](https://github.com/hdmf-dev/hdmf/pull/1189) +- Fixed export of scalar datasets with a compound data type. @stephprince [#1185](https://github.com/hdmf-dev/hdmf/pull/1185) +- Fixed mamba-related error in conda-based GitHub Actions. @rly [#1194](https://github.com/hdmf-dev/hdmf/pull/1194) ## HDMF 3.14.4 (September 4, 2024) diff --git a/src/hdmf/backends/hdf5/h5tools.py b/src/hdmf/backends/hdf5/h5tools.py index da7f78a91..36aeb7c8f 100644 --- a/src/hdmf/backends/hdf5/h5tools.py +++ b/src/hdmf/backends/hdf5/h5tools.py @@ -700,6 +700,10 @@ def __read_dataset(self, h5obj, name=None): kwargs['dtype'] = d.dtype elif h5obj.dtype.kind == 'V': # scalar compound data type kwargs['data'] = np.array(scalar, dtype=h5obj.dtype) + cpd_dt = h5obj.dtype + ref_cols = [check_dtype(ref=cpd_dt[i]) or check_dtype(vlen=cpd_dt[i]) for i in range(len(cpd_dt))] + d = BuilderH5TableDataset(h5obj, self, ref_cols) + kwargs['dtype'] = HDF5IO.__compound_dtype_to_list(h5obj.dtype, d.dtype) else: kwargs["data"] = scalar else: diff --git a/src/hdmf/validate/validator.py b/src/hdmf/validate/validator.py index 2668da1ec..6ce211f96 100644 --- a/src/hdmf/validate/validator.py +++ b/src/hdmf/validate/validator.py @@ -147,7 +147,7 @@ def get_type(data, builder_dtype=None): # Case for h5py.Dataset and other I/O specific array types else: # Compound dtype - if builder_dtype and len(builder_dtype) > 1: + if builder_dtype and isinstance(builder_dtype, list): dtypes = [] string_formats = [] for i in range(len(builder_dtype)): @@ -441,7 +441,7 @@ def validate(self, **kwargs): except EmptyArrayError: # do not validate dtype of empty array. HDMF does not yet set dtype when writing a list/tuple pass - if builder.dtype is not None and len(builder.dtype) > 1 and len(np.shape(builder.data)) == 0: + if isinstance(builder.dtype, list) and len(np.shape(builder.data)) == 0: shape = () # scalar compound dataset elif isinstance(builder.dtype, list): shape = (len(builder.data), ) # only 1D datasets with compound types are supported