Skip to content

Commit c4df1ce

Browse files
committed
Add complex_rectilinear_arrays strategy
1 parent 6792801 commit c4df1ce

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/zarr/testing/strategies.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,51 @@ def make_request(start: int, length: int) -> RangeByteRequest:
594594
return st.lists(key_tuple, min_size=1, max_size=10)
595595

596596

597+
@st.composite
598+
def complex_rectilinear_arrays(
599+
draw: st.DrawFn,
600+
*,
601+
stores: st.SearchStrategy[StoreLike] = stores,
602+
paths: st.SearchStrategy[str] = paths(), # noqa: B008
603+
array_names: st.SearchStrategy = array_names,
604+
attrs: st.SearchStrategy = attrs,
605+
) -> tuple[npt.NDArray[Any], AnyArray]:
606+
"""Generate a rectilinear array with many small chunks.
607+
608+
The shape is derived from the chunk edges (5-10 chunks per dim,
609+
sizes 1-5), exercising higher chunk counts than ``rectilinear_arrays``.
610+
"""
611+
ndim = draw(st.integers(min_value=1, max_value=3))
612+
nchunks = draw(st.integers(min_value=5, max_value=10))
613+
dim_chunks = st.lists(st.integers(min_value=1, max_value=5), min_size=nchunks, max_size=nchunks)
614+
chunk_shapes = draw(st.lists(dim_chunks, min_size=ndim, max_size=ndim))
615+
616+
shape = tuple(sum(dim) for dim in chunk_shapes)
617+
nparray = draw(numpy_arrays(shapes=st.just(shape)))
618+
dim_names = draw(dimension_names(ndim=ndim))
619+
fill_value = draw(st.one_of([st.none(), npst.from_dtype(nparray.dtype)]))
620+
attributes = draw(attrs)
621+
622+
store = draw(stores, label="store")
623+
path = draw(paths, label="array parent")
624+
name = draw(array_names, label="array name")
625+
array_path = _dereference_path(path, name)
626+
627+
root = zarr.open_group(store, mode="w", zarr_format=3)
628+
with zarr.config.set({"array.rectilinear_chunks": True}):
629+
a = root.create_array(
630+
array_path,
631+
shape=shape,
632+
chunks=chunk_shapes,
633+
dtype=nparray.dtype,
634+
fill_value=fill_value,
635+
dimension_names=dim_names,
636+
attributes=attributes,
637+
)
638+
a[:] = nparray
639+
return nparray, a
640+
641+
597642
@st.composite
598643
def chunk_paths(draw: st.DrawFn, ndim: int, numblocks: tuple[int, ...], subset: bool = True) -> str:
599644
blockidx = draw(

0 commit comments

Comments
 (0)