|
19 | 19 | GzipCodec, |
20 | 20 | ShardingCodec, |
21 | 21 | ) |
| 22 | +from zarr.core.array import create_array |
22 | 23 | from zarr.core.array_spec import ArraySpec |
23 | 24 | from zarr.core.buffer import NDBuffer |
24 | 25 | from zarr.core.codec_pipeline import BatchedCodecPipeline |
25 | 26 | from zarr.core.config import BadConfigError, config |
| 27 | +from zarr.core.dtype import get_data_type_from_numpy |
26 | 28 | from zarr.core.indexing import SelectorTuple |
27 | 29 | from zarr.registry import ( |
28 | 30 | fully_qualified_name, |
@@ -52,33 +54,24 @@ def test_config_defaults_set() -> None: |
52 | 54 | "array": { |
53 | 55 | "order": "C", |
54 | 56 | "write_empty_chunks": False, |
55 | | - "v2_default_compressor": { |
56 | | - "numeric": {"id": "zstd", "level": 0, "checksum": False}, |
57 | | - "string": {"id": "zstd", "level": 0, "checksum": False}, |
58 | | - "bytes": {"id": "zstd", "level": 0, "checksum": False}, |
59 | | - }, |
| 57 | + "v2_default_compressor": {"default": {"id": "zstd", "level": 0, "checksum": False}}, |
60 | 58 | "v2_default_filters": { |
61 | | - "numeric": None, |
62 | | - "string": [{"id": "vlen-utf8"}], |
63 | | - "bytes": [{"id": "vlen-bytes"}], |
64 | | - "raw": None, |
| 59 | + "default": None, |
| 60 | + "variable_length_utf8": [{"id": "vlen-utf8"}], |
| 61 | + "fixed_length_ucs4": [{"id": "vlen-utf8"}], |
| 62 | + "fixed_length_ascii": [{"id": "vlen-bytes"}], |
65 | 63 | }, |
66 | | - "v3_default_filters": {"numeric": [], "string": [], "bytes": []}, |
| 64 | + "v3_default_filters": {"default": []}, |
67 | 65 | "v3_default_serializer": { |
68 | | - "numeric": {"name": "bytes", "configuration": {"endian": "little"}}, |
69 | | - "string": {"name": "vlen-utf8"}, |
70 | | - "bytes": {"name": "vlen-bytes"}, |
| 66 | + "default": {"name": "bytes", "configuration": {"endian": "little"}}, |
| 67 | + "variable_length_utf8": {"name": "vlen-utf8"}, |
| 68 | + "fixed_length_ucs4": {"name": "vlen-utf8"}, |
| 69 | + "r*": {"name": "vlen-bytes"}, |
71 | 70 | }, |
72 | 71 | "v3_default_compressors": { |
73 | | - "numeric": [ |
74 | | - {"name": "zstd", "configuration": {"level": 0, "checksum": False}}, |
75 | | - ], |
76 | | - "string": [ |
77 | | - {"name": "zstd", "configuration": {"level": 0, "checksum": False}}, |
78 | | - ], |
79 | | - "bytes": [ |
| 72 | + "default": [ |
80 | 73 | {"name": "zstd", "configuration": {"level": 0, "checksum": False}}, |
81 | | - ], |
| 74 | + ] |
82 | 75 | }, |
83 | 76 | }, |
84 | 77 | "async": {"concurrency": 10, "timeout": None}, |
@@ -306,26 +299,22 @@ class NewCodec2(BytesCodec): |
306 | 299 |
|
307 | 300 | @pytest.mark.parametrize("dtype", ["int", "bytes", "str"]) |
308 | 301 | async def test_default_codecs(dtype: str) -> None: |
309 | | - with config.set( |
310 | | - { |
311 | | - "array.v3_default_compressors": { # test setting non-standard codecs |
312 | | - "numeric": [ |
313 | | - {"name": "gzip", "configuration": {"level": 5}}, |
314 | | - ], |
315 | | - "string": [ |
316 | | - {"name": "gzip", "configuration": {"level": 5}}, |
317 | | - ], |
318 | | - "bytes": [ |
319 | | - {"name": "gzip", "configuration": {"level": 5}}, |
320 | | - ], |
321 | | - } |
322 | | - } |
323 | | - ): |
324 | | - arr = await zarr.api.asynchronous.create_array( |
| 302 | + """ |
| 303 | + Test that the default compressors are sensitive to the current setting of the config. |
| 304 | + """ |
| 305 | + zdtype = get_data_type_from_numpy(dtype) |
| 306 | + expected_compressors = (GzipCodec(),) |
| 307 | + new_conf = { |
| 308 | + f"array.v3_default_compressors.{zdtype._zarr_v3_name}": [ |
| 309 | + c.to_dict() for c in expected_compressors |
| 310 | + ] |
| 311 | + } |
| 312 | + with config.set(new_conf): |
| 313 | + arr = await create_array( |
325 | 314 | shape=(100,), |
326 | 315 | chunks=(100,), |
327 | | - dtype=np.dtype(dtype), |
| 316 | + dtype=dtype, |
328 | 317 | zarr_format=3, |
329 | 318 | store=MemoryStore(), |
330 | 319 | ) |
331 | | - assert arr.compressors == (GzipCodec(),) |
| 320 | + assert arr.compressors == expected_compressors |
0 commit comments