From 88c3d8c6abb2a75bbbfc225ba7e33e94c74460fe Mon Sep 17 00:00:00 2001 From: TomNicholas Date: Wed, 22 Apr 2026 18:17:23 -0400 Subject: [PATCH] fix: clamp HDF chunk dimensions to >= 1 for zero-length datasets Zarr v3 allows `shape=(0,)` but forbids zero-length chunk dimensions, now enforced by zarr-python 3.2.0+. When falling back to `dataset.shape` for chunking, clamp each dim to a minimum of 1 so the HDFParser handles empty HDF5 datasets across all supported zarr versions. --- docs/releases.md | 3 +++ virtualizarr/parsers/hdf/hdf.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/releases.md b/docs/releases.md index 9bc4e562..b1c376c2 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -8,6 +8,9 @@ ### Bug fixes +- Fix `HDFParser` failing on HDF5 datasets with a zero-length dimension under `zarr-python >= 3.2.0`, which forbids zero-length chunk dimensions. Chunk dimensions are now clamped to a minimum of 1 when falling back from dataset shape. + By [Tom Nicholas](https://github.com/TomNicholas). + ### Documentation ### Internal changes diff --git a/virtualizarr/parsers/hdf/hdf.py b/virtualizarr/parsers/hdf/hdf.py index a180a502..d9cef4ff 100644 --- a/virtualizarr/parsers/hdf/hdf.py +++ b/virtualizarr/parsers/hdf/hdf.py @@ -56,7 +56,10 @@ def _construct_manifest_array( ------- ManifestArray """ - chunks = dataset.chunks or dataset.shape + # Clamp each dim to >= 1: zarr v3 allows shape=(0,) but forbids zero-length + # chunk dimensions (enforced by zarr-python >= 3.2.0). See + # https://github.com/zarr-developers/zarr-python/issues/3711. + chunks = dataset.chunks or tuple(max(s, 1) for s in dataset.shape) codecs = codecs_from_dataset(dataset) attrs = _extract_attrs(dataset) dtype = dataset.dtype