diff --git a/docs/releases.md b/docs/releases.md index 0f1ce158..022a76aa 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -1,5 +1,11 @@ # Release notes +## Unreleased + +### Bug Fixes + +HDFParser now includes a `_get_fill_value` function which wraps `dataset.fillvalue` in a try/except AttributeError. + ## v2.6.1 (3rd May 2026) Adds end-to-end support for inlined chunk references in `ChunkManifest` (read via Kerchunk parsers, write via Kerchunk and Icechunk writers), plus Zarr-Python 3.2.0 compatibility and several bug fixes. diff --git a/virtualizarr/parsers/hdf/hdf.py b/virtualizarr/parsers/hdf/hdf.py index aa2051b4..d21c5f7e 100644 --- a/virtualizarr/parsers/hdf/hdf.py +++ b/virtualizarr/parsers/hdf/hdf.py @@ -40,7 +40,10 @@ def _get_fill_value(dataset: H5Dataset): Extract the fill value from an h5py dataset, handling string/bytes dtypes that don't return numpy scalars from dataset.fillvalue. """ - raw = dataset.fillvalue + try: + raw = dataset.fillvalue + except RuntimeError: + return np.ma.default_fill_value(dataset.dtype) if isinstance(raw, bytes): return raw.decode("utf-8", errors="replace") elif isinstance(raw, str): diff --git a/virtualizarr/tests/test_parsers/test_hdf/test_hdf.py b/virtualizarr/tests/test_parsers/test_hdf/test_hdf.py index 9d59224d..fac802a6 100644 --- a/virtualizarr/tests/test_parsers/test_hdf/test_hdf.py +++ b/virtualizarr/tests/test_parsers/test_hdf/test_hdf.py @@ -240,3 +240,20 @@ def test_netcdf_over_https(): ): np.testing.assert_allclose(ds["z"].min().to_numpy(), -6) np.testing.assert_allclose(ds["z"].max().to_numpy(), 817) + + +def test_fillvalue_runtime_error(): + from virtualizarr.parsers.hdf.hdf import _get_fill_value + + dtype = np.dtype("float32") + + class _RuntimeErrorDataset: + @property + def fillvalue(self): + raise RuntimeError("Unable to get fill value") + + dataset = _RuntimeErrorDataset() + dataset.dtype = dtype # type: ignore[attr-defined] + + result = _get_fill_value(dataset) + assert result == np.ma.default_fill_value(dtype)