Skip to content

Commit a1eea78

Browse files
committed
fix property tests
1 parent 07edb89 commit a1eea78

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/zarr/testing/strategies.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,24 @@ def numpy_arrays(
8585
@st.composite # type: ignore[misc]
8686
def np_array_and_chunks(
8787
draw: st.DrawFn, *, arrays: st.SearchStrategy[np.ndarray] = numpy_arrays
88-
) -> tuple[np.ndarray, tuple[int]]: # type: ignore[type-arg]
88+
) -> tuple[np.ndarray, tuple[int, ...]]: # type: ignore[type-arg]
8989
"""A hypothesis strategy to generate small sized random arrays.
9090
9191
Returns: a tuple of the array and a suitable random chunking for it.
9292
"""
9393
array = draw(arrays)
9494
# We want this strategy to shrink towards arrays with smaller number of chunks
9595
# 1. st.integers() shrinks towards smaller values. So we use that to generate number of chunks
96-
numchunks = draw(st.tuples(*[st.integers(min_value=1, max_value=size) for size in array.shape]))
96+
numchunks = draw(
97+
st.tuples(
98+
*[st.integers(min_value=0 if size == 0 else 1, max_value=size) for size in array.shape]
99+
)
100+
)
97101
# 2. and now generate the chunks tuple
98-
chunks = tuple(size // nchunks for size, nchunks in zip(array.shape, numchunks, strict=True))
102+
chunks = tuple(
103+
size // nchunks if nchunks > 0 else 0
104+
for size, nchunks in zip(array.shape, numchunks, strict=True)
105+
)
99106
return (array, chunks)
100107

101108

tests/test_properties.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import hypothesis.extra.numpy as npst # noqa: E402
88
import hypothesis.strategies as st # noqa: E402
9-
from hypothesis import given # noqa: E402
9+
from hypothesis import assume, given # noqa: E402
1010

1111
from zarr.testing.strategies import arrays, basic_indices, numpy_arrays, zarr_formats # noqa: E402
1212

@@ -35,11 +35,13 @@ def test_basic_indexing(data: st.DataObject) -> None:
3535
@given(data=st.data())
3636
def test_vindex(data: st.DataObject) -> None:
3737
zarray = data.draw(arrays())
38+
# integer_array_indices can't handle 0-size dimensions.
39+
assume(all(s > 0 for s in zarray.shape))
3840
nparray = zarray[:]
3941

4042
indexer = data.draw(
4143
npst.integer_array_indices(
42-
shape=nparray.shape, result_shape=npst.array_shapes(max_dims=None)
44+
shape=nparray.shape, result_shape=npst.array_shapes(min_side=1, max_dims=None)
4345
)
4446
)
4547
actual = zarray.vindex[indexer]

0 commit comments

Comments
 (0)