1
- import numpy as np
2
1
import pytest
3
2
from numpy .testing import assert_array_equal
4
3
8
7
9
8
import hypothesis .extra .numpy as npst
10
9
import hypothesis .strategies as st
11
- from hypothesis import given
10
+ from hypothesis import assume , given
12
11
13
12
from zarr .abc .store import Store
14
13
from zarr .core .metadata import ArrayV2Metadata , ArrayV3Metadata
@@ -57,7 +56,7 @@ def test_basic_indexing(data: st.DataObject) -> None:
57
56
actual = zarray [indexer ]
58
57
assert_array_equal (nparray [indexer ], actual )
59
58
60
- new_data = np . ones_like ( actual )
59
+ new_data = data . draw ( npst . arrays ( shape = st . just ( actual . shape ), dtype = nparray . dtype ) )
61
60
zarray [indexer ] = new_data
62
61
nparray [indexer ] = new_data
63
62
assert_array_equal (nparray , zarray [:])
@@ -73,6 +72,12 @@ def test_oindex(data: st.DataObject) -> None:
73
72
actual = zarray .oindex [zindexer ]
74
73
assert_array_equal (nparray [npindexer ], actual )
75
74
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
+
76
81
77
82
@given (data = st .data ())
78
83
def test_vindex (data : st .DataObject ) -> None :
@@ -88,6 +93,14 @@ def test_vindex(data: st.DataObject) -> None:
88
93
actual = zarray .vindex [indexer ]
89
94
assert_array_equal (nparray [indexer ], actual )
90
95
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
+
91
104
92
105
@given (store = stores , meta = array_metadata ()) # type: ignore[misc]
93
106
async def test_roundtrip_array_metadata (
0 commit comments