Skip to content

Commit 42b88dc

Browse files
committed
Add indexing tests
1 parent 32983ba commit 42b88dc

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

tests/test_properties.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import numpy as np
21
import pytest
2+
from numpy.testing import assert_array_equal
33

44
import zarr
55
from zarr import Array
@@ -11,7 +11,6 @@
1111
import hypothesis.strategies as st # noqa
1212
from hypothesis import given, settings # noqa
1313

14-
1514
#### TODO: Provide this in zarr.strategies
1615
# Copied from Xarray
1716
_attr_keys = st.text(st.characters(), min_size=1)
@@ -119,4 +118,25 @@ def arrays(draw, *, stores=stores, arrays=np_arrays, paths=paths, array_names=ar
119118
def test_roundtrip(data):
120119
nparray = data.draw(np_arrays)
121120
zarray = data.draw(arrays(arrays=st.just(nparray)))
122-
np.testing.assert_equal(nparray, zarray[:])
121+
assert_array_equal(nparray, zarray[:])
122+
123+
124+
# @pytest.mark.slow
125+
@given(data=st.data())
126+
def test_basic_indexing(data):
127+
def is_negative_slice(idx):
128+
return isinstance(idx, slice) and idx.step is not None and idx.step < 0
129+
130+
zarray = data.draw(arrays())
131+
nparray = zarray[:]
132+
indexer = data.draw(
133+
npst.basic_indices(shape=nparray.shape).filter(
134+
lambda idxr: (
135+
not (
136+
is_negative_slice(idxr)
137+
or (isinstance(idxr, tuple) and any(is_negative_slice(idx) for idx in idxr))
138+
)
139+
)
140+
)
141+
)
142+
assert_array_equal(nparray[indexer], zarray[indexer])

0 commit comments

Comments
 (0)