22
33from __future__ import annotations
44
5+ from typing import Any
6+
57import numpy as np
68import pytest
79
1719from zarr .storage import MemoryStore
1820
1921
20- def _make_array_spec (
21- shape : tuple [int , ...], dtype : np .dtype
22- ) -> ArraySpec :
22+ def _make_array_spec (shape : tuple [int , ...], dtype : np .dtype [Any ]) -> ArraySpec :
2323 zdtype = get_data_type_from_native_dtype (dtype )
2424 return ArraySpec (
2525 shape = shape ,
@@ -30,7 +30,7 @@ def _make_array_spec(
3030 )
3131
3232
33- def _make_nd_buffer (arr : np .ndarray ) -> zarr .core .buffer .NDBuffer :
33+ def _make_nd_buffer (arr : np .ndarray [ Any , Any ] ) -> zarr .core .buffer .NDBuffer :
3434 return default_buffer_prototype ().nd_buffer .from_numpy_array (arr )
3535
3636
@@ -40,19 +40,19 @@ def _make_nd_buffer(arr: np.ndarray) -> zarr.core.buffer.NDBuffer:
4040
4141
4242class TestSupportsSync :
43- def test_gzip_supports_sync (self ):
43+ def test_gzip_supports_sync (self ) -> None :
4444 assert GzipCodec ().supports_sync
4545
46- def test_zstd_supports_sync (self ):
46+ def test_zstd_supports_sync (self ) -> None :
4747 assert ZstdCodec ().supports_sync
4848
49- def test_bytes_supports_sync (self ):
49+ def test_bytes_supports_sync (self ) -> None :
5050 assert BytesCodec ().supports_sync
5151
52- def test_transpose_supports_sync (self ):
52+ def test_transpose_supports_sync (self ) -> None :
5353 assert TransposeCodec (order = (0 , 1 )).supports_sync
5454
55- def test_sharding_supports_sync (self ):
55+ def test_sharding_supports_sync (self ) -> None :
5656 from zarr .codecs .sharding import ShardingCodec
5757
5858 assert ShardingCodec (chunk_shape = (8 ,)).supports_sync
@@ -64,7 +64,7 @@ def test_sharding_supports_sync(self):
6464
6565
6666class TestGzipCodecSync :
67- def test_roundtrip (self ):
67+ def test_roundtrip (self ) -> None :
6868 codec = GzipCodec (level = 1 )
6969 arr = np .arange (100 , dtype = "float64" )
7070 spec = _make_array_spec (arr .shape , arr .dtype )
@@ -78,7 +78,7 @@ def test_roundtrip(self):
7878
7979
8080class TestZstdCodecSync :
81- def test_roundtrip (self ):
81+ def test_roundtrip (self ) -> None :
8282 codec = ZstdCodec (level = 1 )
8383 arr = np .arange (100 , dtype = "float64" )
8484 spec = _make_array_spec (arr .shape , arr .dtype )
@@ -92,7 +92,7 @@ def test_roundtrip(self):
9292
9393
9494class TestBytesCodecSync :
95- def test_roundtrip (self ):
95+ def test_roundtrip (self ) -> None :
9696 codec = BytesCodec ()
9797 arr = np .arange (100 , dtype = "float64" )
9898 spec = _make_array_spec (arr .shape , arr .dtype )
@@ -108,7 +108,7 @@ def test_roundtrip(self):
108108
109109
110110class TestTransposeCodecSync :
111- def test_roundtrip (self ):
111+ def test_roundtrip (self ) -> None :
112112 codec = TransposeCodec (order = (1 , 0 ))
113113 arr = np .arange (12 , dtype = "float64" ).reshape (3 , 4 )
114114 spec = _make_array_spec (arr .shape , arr .dtype )
@@ -127,29 +127,31 @@ def test_roundtrip(self):
127127
128128
129129class TestPipelineConstruction :
130- def test_from_codecs_valid (self ):
130+ def test_from_codecs_valid (self ) -> None :
131131 pipeline = BatchedCodecPipeline .from_codecs ([BytesCodec (), GzipCodec (level = 1 )])
132132 assert isinstance (pipeline , BatchedCodecPipeline )
133133 assert len (pipeline .bytes_bytes_codecs ) == 1
134134 assert isinstance (pipeline .array_bytes_codec , BytesCodec )
135135
136- def test_from_codecs_accepts_sharding (self ):
136+ def test_from_codecs_accepts_sharding (self ) -> None :
137137 from zarr .codecs .sharding import ShardingCodec
138138
139139 pipeline = BatchedCodecPipeline .from_codecs ([ShardingCodec (chunk_shape = (8 ,))])
140140 assert isinstance (pipeline , BatchedCodecPipeline )
141141 assert pipeline ._all_sync
142142
143- def test_from_codecs_rejects_missing_array_bytes (self ):
143+ def test_from_codecs_rejects_missing_array_bytes (self ) -> None :
144144 with pytest .raises (ValueError , match = "Required ArrayBytesCodec" ):
145145 BatchedCodecPipeline .from_codecs ([GzipCodec ()])
146146
147- def test_from_codecs_with_transpose (self ):
148- pipeline = BatchedCodecPipeline .from_codecs ([
149- TransposeCodec (order = (1 , 0 )),
150- BytesCodec (),
151- GzipCodec (level = 1 ),
152- ])
147+ def test_from_codecs_with_transpose (self ) -> None :
148+ pipeline = BatchedCodecPipeline .from_codecs (
149+ [
150+ TransposeCodec (order = (1 , 0 )),
151+ BytesCodec (),
152+ GzipCodec (level = 1 ),
153+ ]
154+ )
153155 assert len (pipeline .array_array_codecs ) == 1
154156 assert isinstance (pipeline .array_array_codecs [0 ], TransposeCodec )
155157
@@ -161,21 +163,21 @@ def test_from_codecs_with_transpose(self):
161163
162164class TestPipelineRoundtrip :
163165 @pytest .mark .asyncio
164- async def test_encode_decode_single_chunk (self ):
166+ async def test_encode_decode_single_chunk (self ) -> None :
165167 pipeline = BatchedCodecPipeline .from_codecs ([BytesCodec (), GzipCodec (level = 1 )])
166168 arr = np .random .default_rng (42 ).standard_normal ((32 , 32 )).astype ("float64" )
167169 spec = _make_array_spec (arr .shape , arr .dtype )
168170 pipeline = pipeline .evolve_from_array_spec (spec )
169171 nd_buf = _make_nd_buffer (arr )
170172
171173 encoded = await pipeline .encode ([(nd_buf , spec )])
172- decoded = await pipeline .decode ([(list ( encoded )[ 0 ] , spec )])
173- result = list ( decoded )[ 0 ]
174+ decoded = await pipeline .decode ([(next ( iter ( encoded )) , spec )])
175+ result = next ( iter ( decoded ))
174176 assert result is not None
175177 np .testing .assert_array_equal (arr , result .as_numpy_array ())
176178
177179 @pytest .mark .asyncio
178- async def test_encode_decode_multiple_chunks (self ):
180+ async def test_encode_decode_multiple_chunks (self ) -> None :
179181 pipeline = BatchedCodecPipeline .from_codecs ([BytesCodec (), GzipCodec (level = 1 )])
180182 rng = np .random .default_rng (42 )
181183 spec = _make_array_spec ((16 , 16 ), np .dtype ("float64" ))
@@ -185,20 +187,20 @@ async def test_encode_decode_multiple_chunks(self):
185187
186188 encoded = list (await pipeline .encode ([(buf , spec ) for buf in nd_bufs ]))
187189 decoded = list (await pipeline .decode ([(enc , spec ) for enc in encoded ]))
188- for original , dec in zip (chunks , decoded ):
190+ for original , dec in zip (chunks , decoded , strict = False ):
189191 assert dec is not None
190192 np .testing .assert_array_equal (original , dec .as_numpy_array ())
191193
192194 @pytest .mark .asyncio
193- async def test_encode_decode_empty_batch (self ):
195+ async def test_encode_decode_empty_batch (self ) -> None :
194196 pipeline = BatchedCodecPipeline .from_codecs ([BytesCodec (), GzipCodec (level = 1 )])
195197 encoded = await pipeline .encode ([])
196198 assert list (encoded ) == []
197199 decoded = await pipeline .decode ([])
198200 assert list (decoded ) == []
199201
200202 @pytest .mark .asyncio
201- async def test_encode_decode_none_chunk (self ):
203+ async def test_encode_decode_none_chunk (self ) -> None :
202204 pipeline = BatchedCodecPipeline .from_codecs ([BytesCodec (), GzipCodec (level = 1 )])
203205 spec = _make_array_spec ((8 ,), np .dtype ("float64" ))
204206 pipeline = pipeline .evolve_from_array_spec (spec )
@@ -216,7 +218,7 @@ async def test_encode_decode_none_chunk(self):
216218
217219
218220class TestDefaultPipelineSync :
219- def test_create_array_uses_batched_pipeline (self ):
221+ def test_create_array_uses_batched_pipeline (self ) -> None :
220222 store = MemoryStore ()
221223 arr = zarr .create_array (
222224 store ,
@@ -230,7 +232,7 @@ def test_create_array_uses_batched_pipeline(self):
230232 arr [:] = data
231233 np .testing .assert_array_equal (arr [:], data )
232234
233- def test_open_uses_batched_pipeline (self ):
235+ def test_open_uses_batched_pipeline (self ) -> None :
234236 store = MemoryStore ()
235237 arr = zarr .create_array (
236238 store ,
@@ -245,7 +247,7 @@ def test_open_uses_batched_pipeline(self):
245247 assert isinstance (arr2 .async_array .codec_pipeline , BatchedCodecPipeline )
246248 np .testing .assert_array_equal (arr2 [:], data )
247249
248- def test_from_array_uses_batched_pipeline (self ):
250+ def test_from_array_uses_batched_pipeline (self ) -> None :
249251 store1 = MemoryStore ()
250252 arr1 = zarr .create_array (
251253 store1 ,
@@ -261,7 +263,7 @@ def test_from_array_uses_batched_pipeline(self):
261263 assert isinstance (arr2 .async_array .codec_pipeline , BatchedCodecPipeline )
262264 np .testing .assert_array_equal (arr2 [:], data )
263265
264- def test_partial_write (self ):
266+ def test_partial_write (self ) -> None :
265267 store = MemoryStore ()
266268 arr = zarr .create_array (
267269 store ,
@@ -276,7 +278,7 @@ def test_partial_write(self):
276278 expected [5 :15 ] = np .arange (10 , dtype = "int32" ) + 1
277279 np .testing .assert_array_equal (result , expected )
278280
279- def test_zstd_codec (self ):
281+ def test_zstd_codec (self ) -> None :
280282 store = MemoryStore ()
281283 arr = zarr .create_array (
282284 store ,
@@ -289,18 +291,16 @@ def test_zstd_codec(self):
289291 arr [:] = data
290292 np .testing .assert_array_equal (arr [:], data )
291293
292- def test_supports_sync_io (self ):
294+ def test_supports_sync_io (self ) -> None :
293295 """Default pipeline supports sync IO when all codecs are sync."""
294296 pipeline = BatchedCodecPipeline .from_codecs ([BytesCodec (), GzipCodec (level = 1 )])
295297 assert pipeline .supports_sync_io
296298
297- def test_config_switch_to_sync_pipeline_compat (self ):
299+ def test_config_switch_to_sync_pipeline_compat (self ) -> None :
298300 """Verify backwards compat: SyncCodecPipeline config path still works."""
299301 from zarr .experimental .sync_codecs import SyncCodecPipeline
300302
301- zarr .config .set (
302- {"codec_pipeline.path" : "zarr.experimental.sync_codecs.SyncCodecPipeline" }
303- )
303+ zarr .config .set ({"codec_pipeline.path" : "zarr.experimental.sync_codecs.SyncCodecPipeline" })
304304 try :
305305 store = MemoryStore ()
306306 arr = zarr .create_array (store , shape = (10 ,), dtype = "float64" )
0 commit comments