Skip to content

Commit d6dc146

Browse files
committed
rename v2_dtype_kind_to_default_filters_and_compressor to v2_default_compressors
1 parent 8ec16e8 commit d6dc146

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

src/zarr/core/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def reset(self) -> None:
6464
},
6565
"buffer": "zarr.core.buffer.cpu.Buffer",
6666
"ndbuffer": "zarr.core.buffer.cpu.NDBuffer",
67-
"v2_dtype_kind_to_default_filters_and_compressor": {
68-
"biufcmM": ["zstd"],
69-
"U": ["vlen-utf8"],
70-
"OSV": ["vlen-bytes"],
67+
"v2_default_compressors": {
68+
"numeric": ["zstd"],
69+
"unicode": ["vlen-utf8"],
70+
"bytes": ["vlen-bytes"],
7171
},
7272
}
7373
],

src/zarr/core/metadata/v2.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,16 @@ def _default_filters_and_compressor(
341341
) -> tuple[list[dict[str, str]], dict[str, str] | None]:
342342
"""Get the default filters and compressor for a dtype.
343343
344-
The config contains a mapping from numpy dtype kind to the default compressor.
345344
https://numpy.org/doc/2.1/reference/generated/numpy.dtype.kind.html
346345
"""
347-
dtype_kind_to_default_compressor = config.get("v2_dtype_kind_to_default_filters_and_compressor")
348-
for dtype_kinds, filters_and_compressor in dtype_kind_to_default_compressor.items():
349-
if dtype.kind in dtype_kinds:
350-
filters = [{"id": f} for f in filters_and_compressor]
351-
compressor = None
352-
return filters, compressor
353-
return [], None
346+
default_compressors = config.get("v2_default_compressors")
347+
if dtype.kind in "biufcmM":
348+
dtype_key = "numeric"
349+
elif dtype.kind in "U":
350+
dtype_key = "unicode"
351+
elif dtype.kind in "OSV":
352+
dtype_key = "bytes"
353+
else:
354+
raise ValueError(f"Unsupported dtype kind {dtype.kind}")
355+
356+
return [{"id": f} for f in default_compressors[dtype_key]], None

tests/test_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def test_config_defaults_set() -> None:
6363
"vlen-utf8": "zarr.codecs.vlen_utf8.VLenUTF8Codec",
6464
"vlen-bytes": "zarr.codecs.vlen_utf8.VLenBytesCodec",
6565
},
66-
"v2_dtype_kind_to_default_filters_and_compressor": {
67-
"biufcmM": ["zstd"],
68-
"U": ["vlen-utf8"],
69-
"OSV": ["vlen-bytes"],
66+
"v2_default_compressors": {
67+
"numeric": ["zstd"],
68+
"unicode": ["vlen-utf8"],
69+
"bytes": ["vlen-bytes"],
7070
},
7171
}
7272
]

tests/test_v2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_codec_pipeline() -> None:
8484
async def test_v2_encode_decode(dtype):
8585
with config.set(
8686
{
87-
"v2_dtype_kind_to_default_filters_and_compressor": {
88-
"SV": ["vlen-bytes"],
87+
"v2_default_compressors": {
88+
"bytes": ["vlen-bytes"],
8989
},
9090
}
9191
):
@@ -126,9 +126,9 @@ def test_v2_encode_decode_with_data(dtype_value):
126126
dtype, value = dtype_value
127127
with config.set(
128128
{
129-
"v2_dtype_kind_to_default_filters_and_compressor": {
130-
"U": ["vlen-utf8"],
131-
"OSV": ["vlen-bytes"],
129+
"v2_default_compressors": {
130+
"unicode": ["vlen-utf8"],
131+
"bytes": ["vlen-bytes"],
132132
},
133133
}
134134
):
@@ -171,9 +171,9 @@ def test_default_filters_and_compressor(dtype_expected: Any) -> None:
171171
with config.set(
172172
{
173173
"v2_dtype_kind_to_default_filters_and_compressor": {
174-
"biufcmM": ["zstd"],
175-
"U": ["vlen-utf8"],
176-
"OSV": ["vlen-bytes"],
174+
"numeric": ["zstd"],
175+
"unicode": ["vlen-utf8"],
176+
"bytes": ["vlen-bytes"],
177177
},
178178
}
179179
):

0 commit comments

Comments
 (0)