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

Add zstd to old V3 supported codecs #1914

Merged
merged 3 commits into from
May 26, 2024
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
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Docs
Maintenance
~~~~~~~~~~~

* Add Zstd codec to old V3 code path.
By :user:`Ryan Abernathey <rabernat>`

Deprecations
~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion zarr/codecs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa
from numcodecs import *
from numcodecs import get_codec, Blosc, Pickle, Zlib, Delta, AsType, BZ2
from numcodecs import get_codec, Blosc, Pickle, Zlib, Zstd, Delta, AsType, BZ2
from numcodecs.registry import codec_registry
4 changes: 4 additions & 0 deletions zarr/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ def _encode_codec_metadata(cls, codec: Codec) -> Optional[Mapping]:
uri = uri + "lz4/1.0"
elif isinstance(codec, numcodecs.LZMA):
uri = uri + "lzma/1.0"
elif isinstance(codec, numcodecs.Zstd):
uri = uri + "zstd/1.0"
meta = {
"codec": uri,
"configuration": config,
Expand All @@ -439,6 +441,8 @@ def _decode_codec_metadata(cls, meta: Optional[Mapping]) -> Optional[Codec]:
conf["id"] = "lz4"
elif meta["codec"].startswith(uri + "lzma/"):
conf["id"] = "lzma"
elif meta["codec"].startswith(uri + "zstd/"):
conf["id"] = "zstd"
else:
raise NotImplementedError

Expand Down
23 changes: 17 additions & 6 deletions zarr/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

from zarr.codecs import Blosc, Delta, Pickle, Zlib
from zarr.codecs import Blosc, Delta, Pickle, Zlib, Zstd
from zarr.errors import MetadataError
from zarr.meta import (
ZARR_FORMAT,
Expand Down Expand Up @@ -268,17 +268,23 @@ def test_encode_decode_array_dtype_shape():
assert meta_dec["filters"] is None


def test_encode_decode_array_dtype_shape_v3():
@pytest.mark.parametrize("cname", ["zlib", "zstd"])
def test_encode_decode_array_dtype_shape_v3(cname):
Comment on lines +271 to +272
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for review: I made this change to get test coverage to 100%.

if cname == "zlib":
compressor = Zlib(1)
elif cname == "zstd":
compressor = Zstd(1)
meta = dict(
shape=(100,),
chunk_grid=dict(type="regular", chunk_shape=(10,), separator=("/")),
data_type=np.dtype("(10, 10)<f8"),
compressor=Zlib(1),
compressor=compressor,
fill_value=None,
chunk_memory_layout="C",
)

meta_json = """{
meta_json = (
"""{
"attributes": {},
"chunk_grid": {
"chunk_shape": [10],
Expand All @@ -287,7 +293,11 @@ def test_encode_decode_array_dtype_shape_v3():
},
"chunk_memory_layout": "C",
"compressor": {
"codec": "https://purl.org/zarr/spec/codec/zlib/1.0",
"""
+ f"""
"codec": "https://purl.org/zarr/spec/codec/{cname}/1.0",
"""
+ """
"configuration": {
"level": 1
}
Expand All @@ -297,6 +307,7 @@ def test_encode_decode_array_dtype_shape_v3():
"fill_value": null,
"shape": [100, 10, 10 ]
}"""
)

# test encoding
meta_enc = Metadata3.encode_array_metadata(meta)
Expand All @@ -315,7 +326,7 @@ def test_encode_decode_array_dtype_shape_v3():
assert "filters" not in meta_dec


@pytest.mark.parametrize("comp_id", ["gzip", "zlib", "blosc", "bz2", "lz4", "lzma"])
@pytest.mark.parametrize("comp_id", ["gzip", "zlib", "blosc", "bz2", "lz4", "lzma", "zstd"])
def test_decode_metadata_implicit_compressor_config_v3(comp_id):
meta = {
"attributes": {},
Expand Down