Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle uncompressed variables in parsing metadata #207

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Bug fixes

- Exclude empty chunks during `ChunkDict` construction. (:pull:`198`)
By `Gustavo Hidalgo <https://github.com/ghidalgo3>`_.
- Parse uncompressed variable codecs correctly. (:pull:`207`)
By `Gustavo Hidalgo <https://github.com/ghidalgo3>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
9 changes: 9 additions & 0 deletions virtualizarr/tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion virtualizarr/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is len(num_codec_configs) > 0 better? Or not empty(num_codec_configs)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually cover all cases? What if you have an uncompressed variable that does have other codecs?

compressor, *filters = num_codec_configs
else:
compressor, filters = None, []
zarray = ZArray(
chunks=chunk_shape,
compressor=compressor,
Expand Down
Loading