@@ -66,17 +66,19 @@ def test_docstring(codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
66
66
numcodecs .zarr3 .Shuffle ,
67
67
],
68
68
)
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
+ ):
70
72
data = np .arange (0 , 256 , dtype = "uint16" ).reshape ((16 , 16 ))
71
73
72
74
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
73
- a = Array . create (
75
+ a = zarr . create_array (
74
76
store / "generic" ,
75
77
shape = data .shape ,
76
- chunk_shape = (16 , 16 ),
78
+ chunks = (16 , 16 ),
77
79
dtype = data .dtype ,
78
80
fill_value = 0 ,
79
- codecs = [ BytesCodec (), codec_class ()],
81
+ compressors = [ codec_class ()],
80
82
)
81
83
82
84
a [:, :] = data .copy ()
@@ -100,62 +102,61 @@ def test_generic_codec_class(store: StorePath, codec_class: type[numcodecs.zarr3
100
102
)
101
103
def test_generic_filter (
102
104
store : StorePath ,
103
- codec_class : type [numcodecs .zarr3 ._NumcodecsCodec ],
105
+ codec_class : type [numcodecs .zarr3 ._NumcodecsArrayArrayCodec ],
104
106
codec_config : dict [str , JSON ],
105
107
):
106
108
data = np .linspace (0 , 10 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
107
109
108
110
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
109
- a = Array . create (
111
+ a = zarr . create_array (
110
112
store / "generic" ,
111
113
shape = data .shape ,
112
- chunk_shape = (16 , 16 ),
114
+ chunks = (16 , 16 ),
113
115
dtype = data .dtype ,
114
116
fill_value = 0 ,
115
- codecs = [
117
+ filters = [
116
118
codec_class (** codec_config ),
117
- BytesCodec (),
118
119
],
119
120
)
120
121
121
122
a [:, :] = data .copy ()
122
- a = Array . open (store / "generic" )
123
+ a = zarr . open_array (store / "generic" , mode = "r " )
123
124
np .testing .assert_array_equal (data , a [:, :])
124
125
125
126
126
127
def test_generic_filter_bitround (store : StorePath ):
127
128
data = np .linspace (0 , 1 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
128
129
129
130
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
130
- a = Array . create (
131
+ a = zarr . create_array (
131
132
store / "generic_bitround" ,
132
133
shape = data .shape ,
133
- chunk_shape = (16 , 16 ),
134
+ chunks = (16 , 16 ),
134
135
dtype = data .dtype ,
135
136
fill_value = 0 ,
136
- codecs = [numcodecs .zarr3 .BitRound (keepbits = 3 ), BytesCodec ( )],
137
+ filters = [numcodecs .zarr3 .BitRound (keepbits = 3 )],
137
138
)
138
139
139
140
a [:, :] = data .copy ()
140
- a = Array . open (store / "generic_bitround" )
141
+ a = zarr . open_array (store / "generic_bitround" , mode = "r " )
141
142
assert np .allclose (data , a [:, :], atol = 0.1 )
142
143
143
144
144
145
def test_generic_filter_quantize (store : StorePath ):
145
146
data = np .linspace (0 , 10 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
146
147
147
148
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
148
- a = Array . create (
149
+ a = zarr . create_array (
149
150
store / "generic_quantize" ,
150
151
shape = data .shape ,
151
- chunk_shape = (16 , 16 ),
152
+ chunks = (16 , 16 ),
152
153
dtype = data .dtype ,
153
154
fill_value = 0 ,
154
- codecs = [numcodecs .zarr3 .Quantize (digits = 3 ), BytesCodec ( )],
155
+ filters = [numcodecs .zarr3 .Quantize (digits = 3 )],
155
156
)
156
157
157
158
a [:, :] = data .copy ()
158
- a = Array . open (store / "generic_quantize" )
159
+ a = zarr . open_array (store / "generic_quantize" , mode = "r " )
159
160
assert np .allclose (data , a [:, :], atol = 0.001 )
160
161
161
162
@@ -164,27 +165,27 @@ def test_generic_filter_packbits(store: StorePath):
164
165
data [0 :4 , :] = True
165
166
166
167
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
167
- a = Array . create (
168
+ a = zarr . create_array (
168
169
store / "generic_packbits" ,
169
170
shape = data .shape ,
170
- chunk_shape = (16 , 16 ),
171
+ chunks = (16 , 16 ),
171
172
dtype = data .dtype ,
172
173
fill_value = 0 ,
173
- codecs = [numcodecs .zarr3 .PackBits (), BytesCodec ()],
174
+ filters = [numcodecs .zarr3 .PackBits ()],
174
175
)
175
176
176
177
a [:, :] = data .copy ()
177
- a = Array . open (store / "generic_packbits" )
178
+ a = zarr . open_array (store / "generic_packbits" , mode = "r " )
178
179
np .testing .assert_array_equal (data , a [:, :])
179
180
180
181
with pytest .raises (ValueError , match = ".*requires bool dtype.*" ):
181
- Array . create (
182
+ zarr . create_array (
182
183
store / "generic_packbits_err" ,
183
184
shape = data .shape ,
184
- chunk_shape = (16 , 16 ),
185
+ chunks = (16 , 16 ),
185
186
dtype = "uint32" ,
186
187
fill_value = 0 ,
187
- codecs = [numcodecs .zarr3 .PackBits (), BytesCodec ()],
188
+ filters = [numcodecs .zarr3 .PackBits ()],
188
189
)
189
190
190
191
@@ -198,26 +199,30 @@ def test_generic_filter_packbits(store: StorePath):
198
199
numcodecs .zarr3 .JenkinsLookup3 ,
199
200
],
200
201
)
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
+ ):
202
205
data = np .linspace (0 , 10 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
203
206
204
207
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
205
- a = Array . create (
208
+ a = zarr . create_array (
206
209
store / "generic_checksum" ,
207
210
shape = data .shape ,
208
- chunk_shape = (16 , 16 ),
211
+ chunks = (16 , 16 ),
209
212
dtype = data .dtype ,
210
213
fill_value = 0 ,
211
- codecs = [ BytesCodec (), codec_class ()],
214
+ compressors = [ codec_class ()],
212
215
)
213
216
214
217
a [:, :] = data .copy ()
215
- a = Array . open (store / "generic_checksum" )
218
+ a = zarr . open_array (store / "generic_checksum" , mode = "r " )
216
219
np .testing .assert_array_equal (data , a [:, :])
217
220
218
221
219
222
@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
+ ):
221
226
try :
222
227
codec_class ()._codec # noqa: B018
223
228
except ValueError as e :
@@ -231,15 +236,13 @@ def test_generic_bytes_codec(store: StorePath, codec_class: type[numcodecs.zarr3
231
236
data = np .arange (0 , 256 , dtype = "float32" ).reshape ((16 , 16 ))
232
237
233
238
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
234
- a = Array . create (
239
+ a = zarr . create_array (
235
240
store / "generic" ,
236
241
shape = data .shape ,
237
- chunk_shape = (16 , 16 ),
242
+ chunks = (16 , 16 ),
238
243
dtype = data .dtype ,
239
244
fill_value = 0 ,
240
- codecs = [
241
- codec_class (),
242
- ],
245
+ serializer = codec_class (),
243
246
)
244
247
245
248
a [:, :] = data .copy ()
@@ -250,18 +253,22 @@ def test_delta_astype(store: StorePath):
250
253
data = np .linspace (0 , 10 , 256 , dtype = "i8" ).reshape ((16 , 16 ))
251
254
252
255
with pytest .warns (UserWarning , match = EXPECTED_WARNING_STR ):
253
- a = Array . create (
256
+ a = zarr . create_array (
254
257
store / "generic" ,
255
258
shape = data .shape ,
256
- chunk_shape = (16 , 16 ),
259
+ chunks = (16 , 16 ),
257
260
dtype = data .dtype ,
258
261
fill_value = 0 ,
259
- codecs = [
262
+ filters = [
260
263
numcodecs .zarr3 .Delta (dtype = "i8" , astype = "i2" ), # type: ignore[arg-type]
261
- BytesCodec (),
262
264
],
263
265
)
264
266
265
267
a [:, :] = data .copy ()
266
- a = Array . open (store / "generic" )
268
+ a = zarr . open_array (store / "generic" , mode = "r " )
267
269
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