55
66import numpy as np
77import pytest
8- from zarr import Array , AsyncArray , config
8+ from zarr import Array , AsyncArray , config , create_array
9+ from zarr .api .asynchronous import create_array as create_async_array
910from zarr .codecs import (
10- BytesCodec ,
11- ShardingCodec ,
1211 TransposeCodec ,
1312)
1413from zarr .core .buffer import default_buffer_prototype
14+ from zarr .core .chunk_key_encodings import ChunkKeyEncodingParams
1515from zarr .storage import StorePath
1616
1717if TYPE_CHECKING :
18- from zarr .abc .codec import Codec
1918 from zarr .abc .store import Store
2019 from zarr .core .buffer .core import NDArrayLike
2120 from zarr .core .common import MemoryOrder
@@ -73,32 +72,17 @@ async def test_order(
7372 data = np .arange (0 , 256 , dtype = "uint16" ).reshape ((32 , 8 ), order = input_order )
7473 path = "order"
7574 spath = StorePath (store , path = path )
76- codecs_ : list [Codec ] = (
77- [
78- ShardingCodec (
79- chunk_shape = (16 , 8 ),
80- codecs = [
81- TransposeCodec (order = order_from_dim (store_order , data .ndim )),
82- BytesCodec (),
83- ],
84- )
85- ]
86- if with_sharding
87- else [
88- TransposeCodec (order = order_from_dim (store_order , data .ndim )),
89- BytesCodec (),
90- ]
91- )
9275
9376 with config .set ({"array.order" : runtime_write_order }):
94- a = await AsyncArray . create (
77+ a = await create_async_array (
9578 spath ,
9679 shape = data .shape ,
97- chunk_shape = (32 , 8 ),
80+ chunks = (32 , 8 ),
81+ shards = (16 , 8 ) if with_sharding else None ,
9882 dtype = data .dtype ,
9983 fill_value = 0 ,
100- chunk_key_encoding = ( "v2" , "." ),
101- codecs = codecs_ ,
84+ chunk_key_encoding = ChunkKeyEncodingParams ( name = "v2" , separator = "." ),
85+ filters = [ TransposeCodec ( order = order_from_dim ( store_order , data . ndim ))] ,
10286 )
10387
10488 await _AsyncArrayProxy (a )[:, :].set (data )
@@ -135,18 +119,15 @@ def test_order_implicit(
135119 data = np .arange (0 , 256 , dtype = "uint16" ).reshape ((16 , 16 ), order = input_order )
136120 path = "order_implicit"
137121 spath = StorePath (store , path )
138- codecs_ : list [Codec ] | None = (
139- [ShardingCodec (chunk_shape = (8 , 8 ))] if with_sharding else None
140- )
141122
142123 with config .set ({"array.order" : runtime_write_order }):
143- a = Array . create (
124+ a = create_array (
144125 spath ,
145126 shape = data .shape ,
146- chunk_shape = (16 , 16 ),
127+ chunks = (16 , 16 ),
128+ shards = (8 , 8 ) if with_sharding else None ,
147129 dtype = data .dtype ,
148130 fill_value = 0 ,
149- codecs = codecs_ ,
150131 )
151132
152133 a [:, :] = data
@@ -167,10 +148,10 @@ def test_order_implicit(
167148def test_write_partial_chunks (store : Store ) -> None :
168149 data = np .arange (0 , 256 , dtype = "uint16" ).reshape ((16 , 16 ))
169150 spath = StorePath (store )
170- a = Array . create (
151+ a = create_array (
171152 spath ,
172153 shape = data .shape ,
173- chunk_shape = (20 , 20 ),
154+ chunks = (20 , 20 ),
174155 dtype = data .dtype ,
175156 fill_value = 1 ,
176157 )
@@ -182,10 +163,10 @@ async def test_delete_empty_chunks(store: Store) -> None:
182163 data = np .ones ((16 , 16 ))
183164 path = "delete_empty_chunks"
184165 spath = StorePath (store , path )
185- a = await AsyncArray . create (
166+ a = await create_async_array (
186167 spath ,
187168 shape = data .shape ,
188- chunk_shape = (32 , 32 ),
169+ chunks = (32 , 32 ),
189170 dtype = data .dtype ,
190171 fill_value = 1 ,
191172 )
@@ -199,97 +180,89 @@ def test_invalid_metadata(store: Store) -> None:
199180 # LD: Disabled for `zarrs`. Including endianness for a single-byte data type is not invalid.
200181 # spath2 = StorePath(store, "invalid_endian")
201182 # with pytest.raises(TypeError):
202- # Array.create (
183+ # create_array (
203184 # spath2,
204185 # shape=(16, 16),
205- # chunk_shape =(16, 16),
186+ # chunks =(16, 16),
206187 # dtype=np.dtype("uint8"),
207188 # fill_value=0,
208- # codecs=[
209- # BytesCodec(endian="big"),
189+ # filters=[
210190 # TransposeCodec(order=order_from_dim("F", 2)),
211191 # ],
212192 # )
213193 spath3 = StorePath (store , "invalid_order" )
214194 with pytest .raises (TypeError ):
215- Array . create (
195+ create_array (
216196 spath3 ,
217197 shape = (16 , 16 ),
218- chunk_shape = (16 , 16 ),
198+ chunks = (16 , 16 ),
219199 dtype = np .dtype ("uint8" ),
220200 fill_value = 0 ,
221- codecs = [
222- BytesCodec (),
201+ filters = [
223202 TransposeCodec (order = "F" ), # type: ignore[arg-type]
224203 ],
225204 )
226205 spath4 = StorePath (store , "invalid_missing_bytes_codec" )
227206 with pytest .raises (ValueError , match = r".*[Cc]odec.*required" ):
228- Array . create (
207+ create_array (
229208 spath4 ,
230209 shape = (16 , 16 ),
231- chunk_shape = (16 , 16 ),
210+ chunks = (16 , 16 ),
232211 dtype = np .dtype ("uint8" ),
233212 fill_value = 0 ,
234- codecs = [
213+ filters = [
235214 TransposeCodec (order = order_from_dim ("F" , 2 )),
236215 ],
237216 )
238217 spath5 = StorePath (store , "invalid_inner_chunk_shape" )
239218 with pytest .raises (
240219 ValueError , match = r".*shard.*chunk_shape.*array.*shape.*need.*same.*dimensions"
241220 ):
242- Array . create (
221+ create_array (
243222 spath5 ,
244223 shape = (16 , 16 ),
245- chunk_shape = (16 , 16 ),
224+ chunks = (16 , 16 ),
225+ shards = (8 ,),
246226 dtype = np .dtype ("uint8" ),
247227 fill_value = 0 ,
248- codecs = [
249- ShardingCodec (chunk_shape = (8 ,)),
250- ],
251228 )
252229 spath6 = StorePath (store , "invalid_inner_chunk_shape" )
253230 with pytest .raises (
254231 ValueError , match = r".*array.*chunk_shape.*divisible.*shard.*chunk_shape"
255232 ):
256- Array . create (
233+ create_array (
257234 spath6 ,
258235 shape = (16 , 16 ),
259- chunk_shape = (16 , 16 ),
236+ chunks = (16 , 16 ),
237+ shards = (8 , 7 ),
260238 dtype = np .dtype ("uint8" ),
261239 fill_value = 0 ,
262- codecs = [
263- ShardingCodec (chunk_shape = (8 , 7 )),
264- ],
265240 )
266241 # LD: Disabled for `zarrs`. Such checks do not exist.
267242 # Also this is not invalid metadata, should be a separate test.
268243 # spath7 = StorePath(store, "warning_inefficient_codecs")
269244 # with pytest.warns(UserWarning):
270- # Array.create (
245+ # create_array (
271246 # spath7,
272247 # shape=(16, 16),
273- # chunk_shape=(16, 16),
248+ # chunks=(16, 16),
249+ # shards=(8, 8),
274250 # dtype=np.dtype("uint8"),
275251 # fill_value=0,
276- # codecs=[
277- # ShardingCodec(chunk_shape=(8, 8)),
278- # GzipCodec(),
279- # ],
252+ # compressors=[GzipCodec()],
280253 # )
281254
282255
283256async def test_resize (store : Store ) -> None :
284257 data = np .zeros ((16 , 18 ), dtype = "uint16" )
285258 path = "resize"
286259 spath = StorePath (store , path )
287- a = await AsyncArray . create (
260+ a = await create_async_array (
288261 spath ,
289262 shape = data .shape ,
290- chunk_shape = (10 , 10 ),
263+ chunks = (10 , 10 ),
291264 dtype = data .dtype ,
292- chunk_key_encoding = ( "v2" , "." ),
265+ chunk_key_encoding = ChunkKeyEncodingParams ( name = "v2" , separator = "." ),
293266 fill_value = 1 ,
294267 )
295268
0 commit comments