1- import numpy as np
21import pytest
32from numpy .testing import assert_array_equal
43
87
98import hypothesis .extra .numpy as npst
109import hypothesis .strategies as st
11- from hypothesis import given
10+ from hypothesis import assume , given
1211
1312from zarr .abc .store import Store
1413from zarr .core .metadata import ArrayV2Metadata , ArrayV3Metadata
@@ -57,7 +56,7 @@ def test_basic_indexing(data: st.DataObject) -> None:
5756 actual = zarray [indexer ]
5857 assert_array_equal (nparray [indexer ], actual )
5958
60- new_data = np . ones_like ( actual )
59+ new_data = data . draw ( npst . arrays ( shape = st . just ( actual . shape ), dtype = nparray . dtype ) )
6160 zarray [indexer ] = new_data
6261 nparray [indexer ] = new_data
6362 assert_array_equal (nparray , zarray [:])
@@ -73,6 +72,12 @@ def test_oindex(data: st.DataObject) -> None:
7372 actual = zarray .oindex [zindexer ]
7473 assert_array_equal (nparray [npindexer ], actual )
7574
75+ assume (zarray .shards is None ) # GH2834
76+ new_data = data .draw (npst .arrays (shape = st .just (actual .shape ), dtype = nparray .dtype ))
77+ nparray [npindexer ] = new_data
78+ zarray .oindex [zindexer ] = new_data
79+ assert_array_equal (nparray , zarray [:])
80+
7681
7782@given (data = st .data ())
7883def test_vindex (data : st .DataObject ) -> None :
@@ -88,6 +93,14 @@ def test_vindex(data: st.DataObject) -> None:
8893 actual = zarray .vindex [indexer ]
8994 assert_array_equal (nparray [indexer ], actual )
9095
96+ # FIXME!
97+ # when the indexer is such that a value gets overwritten multiple times,
98+ # I think the output depends on chunking.
99+ # new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype))
100+ # nparray[indexer] = new_data
101+ # zarray.vindex[indexer] = new_data
102+ # assert_array_equal(nparray, zarray[:])
103+
91104
92105@given (store = stores , meta = array_metadata ()) # type: ignore[misc]
93106async def test_roundtrip_array_metadata (
0 commit comments