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
@@ -38,7 +37,7 @@ def test_basic_indexing(data: st.DataObject) -> None:
3837 actual = zarray [indexer ]
3938 assert_array_equal (nparray [indexer ], actual )
4039
41- new_data = np . ones_like ( actual )
40+ new_data = data . draw ( npst . arrays ( shape = st . just ( actual . shape ), dtype = nparray . dtype ) )
4241 zarray [indexer ] = new_data
4342 nparray [indexer ] = new_data
4443 assert_array_equal (nparray , zarray [:])
@@ -54,6 +53,11 @@ def test_oindex(data: st.DataObject) -> None:
5453 actual = zarray .oindex [zindexer ]
5554 assert_array_equal (nparray [npindexer ], actual )
5655
56+ new_data = data .draw (npst .arrays (shape = st .just (actual .shape ), dtype = nparray .dtype ))
57+ nparray [npindexer ] = new_data
58+ zarray .oindex [zindexer ] = new_data
59+ assert_array_equal (nparray , zarray [:])
60+
5761
5862@given (data = st .data ())
5963def test_vindex (data : st .DataObject ) -> None :
@@ -69,6 +73,15 @@ def test_vindex(data: st.DataObject) -> None:
6973 actual = zarray .vindex [indexer ]
7074 assert_array_equal (nparray [indexer ], actual )
7175
76+ # FIXME!
77+ # when the indexer is such that a value gets overwritten multiple times,
78+ # I think the output depends on chunking. Honestly I don't know why the 1D indexer works.
79+ assume (indexer [0 ].ndim == 1 )
80+ new_data = data .draw (npst .arrays (shape = st .just (actual .shape ), dtype = nparray .dtype ))
81+ nparray [indexer ] = new_data
82+ zarray .vindex [indexer ] = new_data
83+ assert_array_equal (nparray , zarray [:])
84+
7285
7386@given (store = stores , meta = array_metadata ()) # type: ignore[misc]
7487async def test_roundtrip_array_metadata (
0 commit comments