Skip to content

Commit 3e98c3b

Browse files
authored
Add zstd to old V3 supported codecs (#1914)
* add zstd to old V3 supported codecs * get to full test coverage and add release note * fix pre-commit
1 parent bf89533 commit 3e98c3b

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Docs
3232
Maintenance
3333
~~~~~~~~~~~
3434

35+
* Add Zstd codec to old V3 code path.
36+
By :user:`Ryan Abernathey <rabernat>`
37+
3538
Deprecations
3639
~~~~~~~~~~~~
3740

zarr/codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# flake8: noqa
22
from numcodecs import *
3-
from numcodecs import get_codec, Blosc, Pickle, Zlib, Delta, AsType, BZ2
3+
from numcodecs import get_codec, Blosc, Pickle, Zlib, Zstd, Delta, AsType, BZ2
44
from numcodecs.registry import codec_registry

zarr/meta.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ def _encode_codec_metadata(cls, codec: Codec) -> Optional[Mapping]:
414414
uri = uri + "lz4/1.0"
415415
elif isinstance(codec, numcodecs.LZMA):
416416
uri = uri + "lzma/1.0"
417+
elif isinstance(codec, numcodecs.Zstd):
418+
uri = uri + "zstd/1.0"
417419
meta = {
418420
"codec": uri,
419421
"configuration": config,
@@ -439,6 +441,8 @@ def _decode_codec_metadata(cls, meta: Optional[Mapping]) -> Optional[Codec]:
439441
conf["id"] = "lz4"
440442
elif meta["codec"].startswith(uri + "lzma/"):
441443
conf["id"] = "lzma"
444+
elif meta["codec"].startswith(uri + "zstd/"):
445+
conf["id"] = "zstd"
442446
else:
443447
raise NotImplementedError
444448

zarr/tests/test_meta.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import pytest
77

8-
from zarr.codecs import Blosc, Delta, Pickle, Zlib
8+
from zarr.codecs import Blosc, Delta, Pickle, Zlib, Zstd
99
from zarr.errors import MetadataError
1010
from zarr.meta import (
1111
ZARR_FORMAT,
@@ -268,17 +268,23 @@ def test_encode_decode_array_dtype_shape():
268268
assert meta_dec["filters"] is None
269269

270270

271-
def test_encode_decode_array_dtype_shape_v3():
271+
@pytest.mark.parametrize("cname", ["zlib", "zstd"])
272+
def test_encode_decode_array_dtype_shape_v3(cname):
273+
if cname == "zlib":
274+
compressor = Zlib(1)
275+
elif cname == "zstd":
276+
compressor = Zstd(1)
272277
meta = dict(
273278
shape=(100,),
274279
chunk_grid=dict(type="regular", chunk_shape=(10,), separator=("/")),
275280
data_type=np.dtype("(10, 10)<f8"),
276-
compressor=Zlib(1),
281+
compressor=compressor,
277282
fill_value=None,
278283
chunk_memory_layout="C",
279284
)
280285

281-
meta_json = """{
286+
meta_json = (
287+
"""{
282288
"attributes": {},
283289
"chunk_grid": {
284290
"chunk_shape": [10],
@@ -287,7 +293,11 @@ def test_encode_decode_array_dtype_shape_v3():
287293
},
288294
"chunk_memory_layout": "C",
289295
"compressor": {
290-
"codec": "https://purl.org/zarr/spec/codec/zlib/1.0",
296+
"""
297+
+ f"""
298+
"codec": "https://purl.org/zarr/spec/codec/{cname}/1.0",
299+
"""
300+
+ """
291301
"configuration": {
292302
"level": 1
293303
}
@@ -297,6 +307,7 @@ def test_encode_decode_array_dtype_shape_v3():
297307
"fill_value": null,
298308
"shape": [100, 10, 10 ]
299309
}"""
310+
)
300311

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

317328

318-
@pytest.mark.parametrize("comp_id", ["gzip", "zlib", "blosc", "bz2", "lz4", "lzma"])
329+
@pytest.mark.parametrize("comp_id", ["gzip", "zlib", "blosc", "bz2", "lz4", "lzma", "zstd"])
319330
def test_decode_metadata_implicit_compressor_config_v3(comp_id):
320331
meta = {
321332
"attributes": {},

0 commit comments

Comments
 (0)