Skip to content

Zarr v2 + Zstd: Don't persist the checksum param if false #2655

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

Merged
merged 4 commits into from
Jan 7, 2025
Merged
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
8 changes: 7 additions & 1 deletion src/zarr/core/metadata/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ def _json_convert(
else:
return o.descr
if isinstance(o, numcodecs.abc.Codec):
return o.get_config()
codec_config = o.get_config()

# Hotfix for https://github.com/zarr-developers/zarr-python/issues/2647
if codec_config["id"] == "zstd" and not codec_config.get("checksum", False):
codec_config.pop("checksum", None)
Comment on lines +121 to +123
Copy link
Member

Choose a reason for hiding this comment

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

feels a bit wrong but I don't think this hurts anything.


return codec_config
if np.isscalar(o):
out: Any
if hasattr(o, "dtype") and o.dtype.kind == "M" and hasattr(o, "view"):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_metadata/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import zarr.api.asynchronous
import zarr.storage
from zarr.core.buffer import cpu
from zarr.core.buffer.core import default_buffer_prototype
from zarr.core.group import ConsolidatedMetadata, GroupMetadata
from zarr.core.metadata import ArrayV2Metadata
from zarr.core.metadata.v2 import parse_zarr_format
Expand Down Expand Up @@ -282,3 +283,18 @@ def test_from_dict_extra_fields() -> None:
order="C",
)
assert result == expected


def test_zstd_checksum() -> None:
arr = zarr.create_array(
{},
shape=(10,),
chunks=(10,),
dtype="int32",
compressors={"id": "zstd", "level": 5, "checksum": False},
zarr_format=2,
)
metadata = json.loads(
arr.metadata.to_buffer_dict(default_buffer_prototype())[".zarray"].to_bytes()
)
assert "checksum" not in metadata["compressor"]
Loading