From 5695434e72e3fc361fdc78435531d6c62d228d89 Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Fri, 2 Aug 2024 15:33:13 -0400 Subject: [PATCH 1/2] handle uncompressed variable in parsing metadata --- virtualizarr/tests/test_zarr.py | 9 +++++++++ virtualizarr/zarr.py | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/virtualizarr/tests/test_zarr.py b/virtualizarr/tests/test_zarr.py index 7715d245..a7c12840 100644 --- a/virtualizarr/tests/test_zarr.py +++ b/virtualizarr/tests/test_zarr.py @@ -52,6 +52,15 @@ def test_metadata_roundtrip(tmpdir, vds_with_manifest_arrays: xr.Dataset): assert zarray == vds_with_manifest_arrays.a.data.zarray +def test_uncompressed_variable_roundtrips(tmpdir, vds_with_manifest_arrays): + vds_with_manifest_arrays.a.data.zarray.compressor = None + vds_with_manifest_arrays.a.data.zarray.filters = None + dataset_to_zarr(vds_with_manifest_arrays, tmpdir / "store.zarr") + vds = open_virtual_dataset(tmpdir / "store.zarr", filetype="zarr_v3", indexes={}) + assert vds.a.data.zarray.compressor is None + assert vds.a.data.zarray.filters is None + + def test_zarr_v3_metadata_conformance(tmpdir, vds_with_manifest_arrays: xr.Dataset): """ Checks that the output metadata of an array variable conforms to this spec diff --git a/virtualizarr/zarr.py b/virtualizarr/zarr.py index e5015b36..0cae7ac2 100644 --- a/virtualizarr/zarr.py +++ b/virtualizarr/zarr.py @@ -368,9 +368,14 @@ def metadata_from_zarr_json(filepath: Path) -> tuple[ZArray, list[str], dict]: for codec in metadata["codecs"] if codec["name"] not in ("transpose", "bytes") ] - compressor, *filters = [ + num_codec_configs = [ _configurable_to_num_codec_config(_filter) for _filter in all_codecs ] + # Uncompressed variables may have no codecs + if num_codec_configs: + compressor, *filters = num_codec_configs + else: + compressor, filters = None, [] zarray = ZArray( chunks=chunk_shape, compressor=compressor, From 3c8dd614fa376f8e35ba0265c511eeefc2c521b4 Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Fri, 2 Aug 2024 15:39:27 -0400 Subject: [PATCH 2/2] docs --- docs/releases.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/releases.rst b/docs/releases.rst index f472db05..454ab8b3 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -23,6 +23,8 @@ Bug fixes - Exclude empty chunks during `ChunkDict` construction. (:pull:`198`) By `Gustavo Hidalgo `_. +- Parse uncompressed variable codecs correctly. (:pull:`207`) + By `Gustavo Hidalgo `_. Documentation ~~~~~~~~~~~~~