@@ -66,17 +66,19 @@ def test_docstring(codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
6666 numcodecs .zarr3 .Shuffle ,
6767 ],
6868)
69- def test_generic_codec_class (store : StorePath , codec_class : type [numcodecs .zarr3 ._NumcodecsCodec ]):
69+ def test_generic_compressor (
70+ store : StorePath , codec_class : type [numcodecs .zarr3 ._NumcodecsBytesBytesCodec ]
71+ ):
7072 data = np .arange (0 , 256 , dtype = "uint16" ).reshape ((16 , 16 ))
7173
7274 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
73- a = Array . create (
75+ a = zarr . create_array (
7476 store / "generic" ,
7577 shape = data .shape ,
76- chunk_shape = (16 , 16 ),
78+ chunks = (16 , 16 ),
7779 dtype = data .dtype ,
7880 fill_value = 0 ,
79- codecs = [ BytesCodec (), codec_class ()],
81+ compressors = [ codec_class ()],
8082 )
8183
8284 a [:, :] = data .copy ()
@@ -100,62 +102,61 @@ def test_generic_codec_class(store: StorePath, codec_class: type[numcodecs.zarr3
100102)
101103def test_generic_filter (
102104 store : StorePath ,
103- codec_class : type [numcodecs .zarr3 ._NumcodecsCodec ],
105+ codec_class : type [numcodecs .zarr3 ._NumcodecsArrayArrayCodec ],
104106 codec_config : dict [str , JSON ],
105107):
106108 data = np .linspace (0 , 10 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
107109
108110 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
109- a = Array . create (
111+ a = zarr . create_array (
110112 store / "generic" ,
111113 shape = data .shape ,
112- chunk_shape = (16 , 16 ),
114+ chunks = (16 , 16 ),
113115 dtype = data .dtype ,
114116 fill_value = 0 ,
115- codecs = [
117+ filters = [
116118 codec_class (** codec_config ),
117- BytesCodec (),
118119 ],
119120 )
120121
121122 a [:, :] = data .copy ()
122- a = Array . open (store / "generic" )
123+ a = zarr . open_array (store / "generic" , mode = "r " )
123124 np .testing .assert_array_equal (data , a [:, :])
124125
125126
126127def test_generic_filter_bitround (store : StorePath ):
127128 data = np .linspace (0 , 1 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
128129
129130 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
130- a = Array . create (
131+ a = zarr . create_array (
131132 store / "generic_bitround" ,
132133 shape = data .shape ,
133- chunk_shape = (16 , 16 ),
134+ chunks = (16 , 16 ),
134135 dtype = data .dtype ,
135136 fill_value = 0 ,
136- codecs = [numcodecs .zarr3 .BitRound (keepbits = 3 ), BytesCodec ( )],
137+ filters = [numcodecs .zarr3 .BitRound (keepbits = 3 )],
137138 )
138139
139140 a [:, :] = data .copy ()
140- a = Array . open (store / "generic_bitround" )
141+ a = zarr . open_array (store / "generic_bitround" , mode = "r " )
141142 assert np .allclose (data , a [:, :], atol = 0.1 )
142143
143144
144145def test_generic_filter_quantize (store : StorePath ):
145146 data = np .linspace (0 , 10 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
146147
147148 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
148- a = Array . create (
149+ a = zarr . create_array (
149150 store / "generic_quantize" ,
150151 shape = data .shape ,
151- chunk_shape = (16 , 16 ),
152+ chunks = (16 , 16 ),
152153 dtype = data .dtype ,
153154 fill_value = 0 ,
154- codecs = [numcodecs .zarr3 .Quantize (digits = 3 ), BytesCodec ( )],
155+ filters = [numcodecs .zarr3 .Quantize (digits = 3 )],
155156 )
156157
157158 a [:, :] = data .copy ()
158- a = Array . open (store / "generic_quantize" )
159+ a = zarr . open_array (store / "generic_quantize" , mode = "r " )
159160 assert np .allclose (data , a [:, :], atol = 0.001 )
160161
161162
@@ -164,27 +165,27 @@ def test_generic_filter_packbits(store: StorePath):
164165 data [0 :4 , :] = True
165166
166167 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
167- a = Array . create (
168+ a = zarr . create_array (
168169 store / "generic_packbits" ,
169170 shape = data .shape ,
170- chunk_shape = (16 , 16 ),
171+ chunks = (16 , 16 ),
171172 dtype = data .dtype ,
172173 fill_value = 0 ,
173- codecs = [numcodecs .zarr3 .PackBits (), BytesCodec ()],
174+ filters = [numcodecs .zarr3 .PackBits ()],
174175 )
175176
176177 a [:, :] = data .copy ()
177- a = Array . open (store / "generic_packbits" )
178+ a = zarr . open_array (store / "generic_packbits" , mode = "r " )
178179 np .testing .assert_array_equal (data , a [:, :])
179180
180181 with pytest .raises (ValueError , match = ".*requires bool dtype.*" ):
181- Array . create (
182+ zarr . create_array (
182183 store / "generic_packbits_err" ,
183184 shape = data .shape ,
184- chunk_shape = (16 , 16 ),
185+ chunks = (16 , 16 ),
185186 dtype = "uint32" ,
186187 fill_value = 0 ,
187- codecs = [numcodecs .zarr3 .PackBits (), BytesCodec ()],
188+ filters = [numcodecs .zarr3 .PackBits ()],
188189 )
189190
190191
@@ -198,26 +199,30 @@ def test_generic_filter_packbits(store: StorePath):
198199 numcodecs .zarr3 .JenkinsLookup3 ,
199200 ],
200201)
201- def test_generic_checksum (store : StorePath , codec_class : type [numcodecs .zarr3 ._NumcodecsCodec ]):
202+ def test_generic_checksum (
203+ store : StorePath , codec_class : type [numcodecs .zarr3 ._NumcodecsBytesBytesCodec ]
204+ ):
202205 data = np .linspace (0 , 10 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
203206
204207 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
205- a = Array . create (
208+ a = zarr . create_array (
206209 store / "generic_checksum" ,
207210 shape = data .shape ,
208- chunk_shape = (16 , 16 ),
211+ chunks = (16 , 16 ),
209212 dtype = data .dtype ,
210213 fill_value = 0 ,
211- codecs = [ BytesCodec (), codec_class ()],
214+ compressors = [ codec_class ()],
212215 )
213216
214217 a [:, :] = data .copy ()
215- a = Array . open (store / "generic_checksum" )
218+ a = zarr . open_array (store / "generic_checksum" , mode = "r " )
216219 np .testing .assert_array_equal (data , a [:, :])
217220
218221
219222@pytest .mark .parametrize ("codec_class" , [numcodecs .zarr3 .PCodec , numcodecs .zarr3 .ZFPY ])
220- def test_generic_bytes_codec (store : StorePath , codec_class : type [numcodecs .zarr3 ._NumcodecsCodec ]):
223+ def test_generic_bytes_codec (
224+ store : StorePath , codec_class : type [numcodecs .zarr3 ._NumcodecsArrayBytesCodec ]
225+ ):
221226 try :
222227 codec_class ()._codec # noqa: B018
223228 except ValueError as e :
@@ -231,15 +236,13 @@ def test_generic_bytes_codec(store: StorePath, codec_class: type[numcodecs.zarr3
231236 data = np .arange (0 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
232237
233238 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
234- a = Array . create (
239+ a = zarr . create_array (
235240 store / "generic" ,
236241 shape = data .shape ,
237- chunk_shape = (16 , 16 ),
242+ chunks = (16 , 16 ),
238243 dtype = data .dtype ,
239244 fill_value = 0 ,
240- codecs = [
241- codec_class (),
242- ],
245+ serializer = codec_class (),
243246 )
244247
245248 a [:, :] = data .copy ()
@@ -250,18 +253,22 @@ def test_delta_astype(store: StorePath):
250253 data = np .linspace (0 , 10 , 256 , dtype = "i8" ).reshape ((16 , 16 ))
251254
252255 with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
253- a = Array . create (
256+ a = zarr . create_array (
254257 store / "generic" ,
255258 shape = data .shape ,
256- chunk_shape = (16 , 16 ),
259+ chunks = (16 , 16 ),
257260 dtype = data .dtype ,
258261 fill_value = 0 ,
259- codecs = [
262+ filters = [
260263 numcodecs .zarr3 .Delta (dtype = "i8" , astype = "i2" ), # type: ignore[arg-type]
261- BytesCodec (),
262264 ],
263265 )
264266
265267 a [:, :] = data .copy ()
266- a = Array . open (store / "generic" )
268+ a = zarr . open_array (store / "generic" , mode = "r " )
267269 np .testing .assert_array_equal (data , a [:, :])
270+
271+
272+ def test_repr ():
273+ codec = numcodecs .zarr3 .LZ4 (level = 5 )
274+ assert repr (codec ) == "LZ4(codec_name='numcodecs.lz4', codec_config={'level': 5})"
0 commit comments