@@ -80,36 +80,43 @@ def test_codec_pipeline() -> None:
8080
8181@pytest .mark .parametrize ("dtype" , ["|S" , "|V" ])
8282async def test_v2_encode_decode (dtype ):
83- store = zarr .storage .MemoryStore (mode = "w" )
84- g = zarr .group (store = store , zarr_format = 2 )
85- g .create_array (
86- name = "foo" ,
87- shape = (3 ,),
88- chunks = (3 ,),
89- dtype = dtype ,
90- fill_value = b"X" ,
91- )
92-
93- result = await store .get ("foo/.zarray" , zarr .core .buffer .default_buffer_prototype ())
94- assert result is not None
95-
96- serialized = json .loads (result .to_bytes ())
97- expected = {
98- "chunks" : [3 ],
99- "dtype" : f"{ dtype } 0" ,
100- "fill_value" : "WA==" ,
101- "filters" : None ,
102- "order" : "C" ,
103- "shape" : [3 ],
104- "zarr_format" : 2 ,
105- "dimension_separator" : "." ,
106- }
107- del serialized ["compressor" ]
108- assert serialized == expected
83+ with config .set (
84+ {
85+ "v2_dtype_kind_to_default_filters_and_compressor" : {
86+ "OSUV" : ["vlen-bytes" ],
87+ },
88+ }
89+ ):
90+ store = zarr .storage .MemoryStore (mode = "w" )
91+ g = zarr .group (store = store , zarr_format = 2 )
92+ g .create_array (
93+ name = "foo" ,
94+ shape = (3 ,),
95+ chunks = (3 ,),
96+ dtype = dtype ,
97+ fill_value = b"X" ,
98+ )
99+
100+ result = await store .get ("foo/.zarray" , zarr .core .buffer .default_buffer_prototype ())
101+ assert result is not None
102+
103+ serialized = json .loads (result .to_bytes ())
104+ expected = {
105+ "chunks" : [3 ],
106+ "compressor" : None ,
107+ "dtype" : f"{ dtype } 0" ,
108+ "fill_value" : "WA==" ,
109+ "filters" : [{"id" : "vlen-bytes" }],
110+ "order" : "C" ,
111+ "shape" : [3 ],
112+ "zarr_format" : 2 ,
113+ "dimension_separator" : "." ,
114+ }
115+ assert serialized == expected
109116
110- data = zarr .open_array (store = store , path = "foo" )[:]
111- expected = np .full ((3 ,), b"X" , dtype = dtype )
112- np .testing .assert_equal (data , expected )
117+ data = zarr .open_array (store = store , path = "foo" )[:]
118+ expected = np .full ((3 ,), b"X" , dtype = dtype )
119+ np .testing .assert_equal (data , expected )
113120
114121
115122@pytest .mark .parametrize ("dtype" , [str , "str" ])
@@ -133,18 +140,19 @@ def test_v2_filters_codecs(filters: Any) -> None:
133140
134141
135142@pytest .mark .parametrize (
136- "dtype_compressor " ,
137- [["b" , "zstd" ], ["i" , "zstd" ], ["f" , "zstd" ], ["|S1" , "vlen-bytes " ], ["|U1" , "vlen-bytes " ]],
143+ "dtype_expected " ,
144+ [["b" , "zstd" ], ["i" , "zstd" ], ["f" , "zstd" ], ["|S1" , "vlen-utf8 " ], ["|U1" , "vlen-utf8 " ]],
138145)
139- def test_default_compressors ( dtype_compressor : Any ) -> None :
146+ def test_default_filters_and_compressor ( dtype_expected : Any ) -> None :
140147 with config .set (
141148 {
142- "v2_dtype_kind_to_default_compressor " : {
143- "biufcmM" : "zstd" ,
144- "OSUV" : "vlen-bytes" ,
149+ "v2_dtype_kind_to_default_filters_and_compressor " : {
150+ "biufcmM" : [ "zstd" ] ,
151+ "OSUV" : [ "vlen-utf8" ] ,
145152 },
146153 }
147154 ):
148- dtype , expected_compressor = dtype_compressor
155+ dtype , expected = dtype_expected
149156 arr = zarr .create (shape = (10 ,), path = "foo" , store = {}, zarr_format = 2 , dtype = dtype )
150- assert arr .metadata .compressor .codec_id == expected_compressor
157+ assert arr .metadata .filters [0 ].codec_id == expected
158+ print (arr .metadata )
0 commit comments