1313import zarr
1414from zarr .abc .store import RangeByteRequest , Store
1515from zarr .codecs .bytes import BytesCodec
16- from zarr .core .array import Array
16+ from zarr .codecs .crc32c_ import Crc32cCodec
17+ from zarr .codecs .sharding import SUBCHUNK_WRITE_ORDER , ShardingCodec , SubchunkWriteOrder
18+ from zarr .core .array import Array , CompressorsLike , SerializerLike
1719from zarr .core .chunk_grids import RegularChunkGrid
1820from zarr .core .chunk_key_encodings import DefaultChunkKeyEncoding
1921from zarr .core .common import JSON , ZarrFormat
@@ -128,6 +130,9 @@ def dimension_names(draw: st.DrawFn, *, ndim: int | None = None) -> list[None |
128130 return draw (st .none () | st .lists (st .none () | simple_text , min_size = ndim , max_size = ndim )) # type: ignore[arg-type]
129131
130132
133+ subchunk_write_orders : st .SearchStrategy [SubchunkWriteOrder ] = st .sampled_from (SUBCHUNK_WRITE_ORDER )
134+
135+
131136@st .composite
132137def array_metadata (
133138 draw : st .DrawFn ,
@@ -249,6 +254,7 @@ def arrays(
249254 arrays : st .SearchStrategy | None = None ,
250255 attrs : st .SearchStrategy = attrs ,
251256 zarr_formats : st .SearchStrategy = zarr_formats ,
257+ subchunk_write_orders : SearchStrategy [SubchunkWriteOrder ] = subchunk_write_orders ,
252258) -> AnyArray :
253259 store = draw (stores , label = "store" )
254260 path = draw (paths , label = "array parent" )
@@ -260,12 +266,22 @@ def arrays(
260266 nparray = draw (arrays , label = "array data" )
261267 chunk_shape = draw (chunk_shapes (shape = nparray .shape ), label = "chunk shape" )
262268 dim_names : None | list [str | None ] = None
269+ serializer : SerializerLike = "auto"
270+ compressors_unsearched : CompressorsLike = "auto"
263271 if zarr_format == 3 and all (c > 0 for c in chunk_shape ):
264272 shard_shape = draw (
265273 st .none () | shard_shapes (shape = nparray .shape , chunk_shape = chunk_shape ),
266274 label = "shard shape" ,
267275 )
268276 dim_names = draw (dimension_names (ndim = nparray .ndim ), label = "dimension names" )
277+ subchunk_write_order = draw (subchunk_write_orders )
278+ serializer = ShardingCodec (
279+ subchunk_write_order = subchunk_write_order ,
280+ codecs = [BytesCodec ()],
281+ index_codecs = [BytesCodec (), Crc32cCodec ()],
282+ chunk_shape = chunk_shape ,
283+ )
284+ compressors_unsearched = None
269285 else :
270286 shard_shape = None
271287 # test that None works too.
@@ -284,9 +300,10 @@ def arrays(
284300 shards = shard_shape ,
285301 dtype = nparray .dtype ,
286302 attributes = attributes ,
287- # compressor=compressor , # FIXME
303+ compressors = compressors_unsearched , # FIXME
288304 fill_value = fill_value ,
289305 dimension_names = dim_names ,
306+ serializer = serializer ,
290307 )
291308
292309 assert isinstance (a , Array )
@@ -298,7 +315,8 @@ def arrays(
298315 assert isinstance (root [array_path ], Array )
299316 assert nparray .shape == a .shape
300317 assert chunk_shape == a .chunks
301- assert shard_shape == a .shards
318+ if shard_shape is not None :
319+ assert shard_shape == a .shards
302320 assert a .basename == name , (a .basename , name )
303321 assert dict (a .attrs ) == expected_attrs
304322
0 commit comments