Skip to content

Commit 7982f86

Browse files
committed
Add more setitem property tests
1 parent 870265a commit 7982f86

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tests/test_properties.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import numpy as np
21
import pytest
32
from numpy.testing import assert_array_equal
43

54
pytest.importorskip("hypothesis")
65

76
import hypothesis.extra.numpy as npst
87
import hypothesis.strategies as st
9-
from hypothesis import given
8+
from hypothesis import assume, given
109

1110
from zarr.testing.strategies import (
1211
arrays,
@@ -32,7 +31,7 @@ def test_basic_indexing(data: st.DataObject) -> None:
3231
actual = zarray[indexer]
3332
assert_array_equal(nparray[indexer], actual)
3433

35-
new_data = np.ones_like(actual)
34+
new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype))
3635
zarray[indexer] = new_data
3736
nparray[indexer] = new_data
3837
assert_array_equal(nparray, zarray[:])
@@ -48,6 +47,11 @@ def test_oindex(data: st.DataObject) -> None:
4847
actual = zarray.oindex[zindexer]
4948
assert_array_equal(nparray[npindexer], actual)
5049

50+
new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype))
51+
nparray[npindexer] = new_data
52+
zarray.oindex[zindexer] = new_data
53+
assert_array_equal(nparray, zarray[:])
54+
5155

5256
@given(data=st.data())
5357
def test_vindex(data: st.DataObject) -> None:
@@ -63,6 +67,15 @@ def test_vindex(data: st.DataObject) -> None:
6367
actual = zarray.vindex[indexer]
6468
assert_array_equal(nparray[indexer], actual)
6569

70+
# FIXME!
71+
# when the indexer is such that a value gets overwritten multiple times,
72+
# I think the output depends on chunking. Honestly I don't know why the 1D indexer works.
73+
assume(indexer[0].ndim == 1)
74+
new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype))
75+
nparray[indexer] = new_data
76+
zarray.vindex[indexer] = new_data
77+
assert_array_equal(nparray, zarray[:])
78+
6679

6780
# @st.composite
6881
# def advanced_indices(draw, *, shape):

0 commit comments

Comments
 (0)