Skip to content

Commit 67d694e

Browse files
committed
More proptest updates
1 parent d8dcd2d commit 67d694e

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

src/zarr/testing/strategies.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,41 @@ def rectilinear_chunks(draw: st.DrawFn, *, shape: tuple[int, ...]) -> list[list[
233233
for size in shape:
234234
assert size > 0
235235
if size > 1:
236-
# Limit max chunks to 20 to avoid performance issues with large chunk grids
237-
max_chunks = min(size - 1, 20)
238-
nchunks = draw(st.integers(min_value=1, max_value=max_chunks))
239-
dividers = sorted(
240-
draw(
241-
st.lists(
242-
st.integers(min_value=1, max_value=size - 1),
243-
min_size=nchunks - 1,
244-
max_size=nchunks - 1,
245-
unique=True,
236+
mode = draw(st.sampled_from(["expanded", "rle"]))
237+
if mode == "expanded":
238+
event("rectilinear expanded")
239+
# Limit max chunks to 20 to avoid performance issues with large chunk grids
240+
max_chunks = min(size - 1, 20)
241+
nchunks = draw(st.integers(min_value=1, max_value=max_chunks))
242+
dividers = sorted(
243+
draw(
244+
st.lists(
245+
st.integers(min_value=1, max_value=size - 1),
246+
min_size=nchunks - 1,
247+
max_size=nchunks - 1,
248+
unique=True,
249+
)
246250
)
247251
)
248-
)
249-
chunk_shapes.append(
250-
[a - b for a, b in zip(dividers + [size], [0] + dividers, strict=False)]
251-
)
252+
chunk_shapes.append(
253+
[a - b for a, b in zip(dividers + [size], [0] + dividers, strict=False)]
254+
)
255+
else:
256+
# RLE mode: uniform chunks with optional remainder
257+
max_chunk_size = min(size, 20)
258+
chunk_size = draw(st.integers(min_value=1, max_value=max_chunk_size))
259+
n_full = size // chunk_size
260+
remainder = size % chunk_size
261+
chunks_list = [chunk_size] * n_full
262+
if remainder > 0:
263+
chunks_list.append(remainder)
264+
# Optionally shuffle to create non-contiguous duplicate patterns
265+
if draw(st.booleans()):
266+
event("rectilinear rle shuffled")
267+
chunks_list = draw(st.permutations(chunks_list))
268+
else:
269+
event("rectilinear rle")
270+
chunk_shapes.append(list(chunks_list))
252271
else:
253272
chunk_shapes.append([1])
254273
return chunk_shapes

tests/test_properties.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
array_metadata,
2525
arrays,
2626
basic_indices,
27+
chunk_grids,
2728
numpy_arrays,
2829
orthogonal_indices,
2930
simple_arrays,
@@ -373,3 +374,14 @@ def test_array_metadata_meets_spec(meta: ArrayV2Metadata | ArrayV3Metadata) -> N
373374
assert serialized_complex_float_is_valid(asdict_dict["fill_value"])
374375
elif dtype_native.kind in ("M", "m") and np.isnat(meta.fill_value):
375376
assert asdict_dict["fill_value"] == -9223372036854775808
377+
378+
379+
@given(
380+
shape=npst.array_shapes(min_dims=1, max_dims=4, min_side=1, max_side=100),
381+
data=st.data(),
382+
)
383+
@settings(max_examples=200)
384+
def test_chunk_grid_roundtrip(shape: tuple[int, ...], data: st.DataObject) -> None:
385+
grid = data.draw(chunk_grids(shape=shape))
386+
roundtripped = type(grid).from_dict(grid.to_dict())
387+
assert roundtripped == grid

0 commit comments

Comments
 (0)