Skip to content

Commit

Permalink
Zstd: Don't persist the checksum param if false (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
normanrz authored Jan 7, 2025
1 parent bb8ab0f commit f9c2024
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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)

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"]

0 comments on commit f9c2024

Please sign in to comment.