Skip to content

Commit 6954b60

Browse files
committed
test v3_default_codecs
1 parent 12dfaf4 commit 6954b60

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/zarr/core/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def reset(self) -> None:
4949
"string": "vlen-utf8",
5050
"bytes": "vlen-bytes",
5151
},
52+
"v3_default_codecs": {
53+
"numeric": ["bytes", "zstd"],
54+
"string": ["vlen-utf8"],
55+
"bytes": ["vlen-bytes"],
56+
},
5257
},
5358
"async": {"concurrency": 10, "timeout": None},
5459
"threading": {"max_workers": None},

src/zarr/core/metadata/v2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ def _default_filters_and_compressor(
336336
337337
https://numpy.org/doc/2.1/reference/generated/numpy.dtype.kind.html
338338
"""
339-
dtype = np.dtype(dtype)
340339
default_compressor = config.get("array.v2_default_compressor")
341340
if dtype.kind in "biufcmM":
342341
dtype_key = "numeric"

tests/test_config.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from zarr import Array, zeros
1212
from zarr.abc.codec import CodecInput, CodecOutput, CodecPipeline
1313
from zarr.abc.store import ByteSetter, Store
14-
from zarr.codecs import BloscCodec, BytesCodec, Crc32cCodec, ShardingCodec
14+
from zarr.codecs import BloscCodec, BytesCodec, Crc32cCodec, ShardingCodec, TransposeCodec, GzipCodec, VLenBytesCodec, \
15+
VLenUTF8Codec
1516
from zarr.core.array_spec import ArraySpec
1617
from zarr.core.buffer import NDBuffer
1718
from zarr.core.codec_pipeline import BatchedCodecPipeline
@@ -239,3 +240,18 @@ def test_config_buffer_implementation() -> None:
239240
)
240241
arr_Crc32c[:] = data2d
241242
assert np.array_equal(arr_Crc32c[:], data2d)
243+
244+
@pytest.mark.parametrize("dtype", ["int", "bytes", "str"])
245+
def test_default_codecs(dtype:str) -> None:
246+
with config.set({"array.v3_default_codecs": {
247+
"numeric": ["bytes", "gzip"], # test setting non-standard codecs
248+
"string": ["vlen-utf8"],
249+
"bytes": ["vlen-bytes"],
250+
}}):
251+
arr = zeros(shape=(100), store=StoreExpectingTestBuffer(), dtype=dtype)
252+
if dtype == "int":
253+
assert arr.metadata.codecs == [BytesCodec(), GzipCodec()]
254+
elif dtype == "bytes":
255+
assert arr.metadata.codecs == [VLenBytesCodec()]
256+
elif dtype == "str":
257+
assert arr.metadata.codecs == [VLenUTF8Codec()]

0 commit comments

Comments
 (0)