@@ -105,54 +105,52 @@ def test_array_creates_implicit_groups(array):
105
105
# this decorator removes timeout; not ideal but it should avoid intermittent CI failures
106
106
107
107
108
+ @pytest .mark .asyncio
108
109
@settings (deadline = None )
109
110
@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
110
111
@given (data = st .data ())
111
- def test_basic_indexing (data : st .DataObject ) -> None :
112
+ async def test_basic_indexing (data : st .DataObject ) -> None :
112
113
zarray = data .draw (simple_arrays ())
113
114
nparray = zarray [:]
114
115
indexer = data .draw (basic_indices (shape = nparray .shape ))
116
+
117
+ # sync get
115
118
actual = zarray [indexer ]
116
119
assert_array_equal (nparray [indexer ], actual )
117
120
121
+ # async get
122
+ async_zarray = zarray ._async_array
123
+ actual = await async_zarray .getitem (indexer )
124
+ assert_array_equal (nparray [indexer ], actual )
125
+
126
+ # sync set
118
127
new_data = data .draw (numpy_arrays (shapes = st .just (actual .shape ), dtype = nparray .dtype ))
119
128
zarray [indexer ] = new_data
120
129
nparray [indexer ] = new_data
121
130
assert_array_equal (nparray , zarray [:])
122
131
123
-
124
- @pytest .mark .asyncio
125
- @settings (deadline = None )
126
- @pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
127
- @given (data = st .data ())
128
- async def test_basic_indexing_async (data : st .DataObject ) -> None :
129
- zarray = data .draw (simple_arrays ())
130
- nparray = zarray [:]
131
- indexer = data .draw (basic_indices (shape = nparray .shape ))
132
- async_zarray = zarray ._async_array
133
-
134
- actual = await async_zarray .getitem (indexer )
135
- assert_array_equal (nparray [indexer ], actual )
136
-
137
- # TODO test async setitem
138
- # new_data = data.draw(numpy_arrays(shapes=st.just(actual.shape), dtype=nparray.dtype))
139
- # asyncio.run(async_zarray.setitem(indexer, new_data))
140
- # nparray[indexer] = new_data
141
- # result = asyncio.run(async_zarray.getitem(indexer))
142
- # assert_array_equal(nparray, result)
132
+ # TODO test async setitem?
143
133
144
134
135
+ @pytest .mark .asyncio
145
136
@given (data = st .data ())
146
137
@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
147
- def test_oindex (data : st .DataObject ) -> None :
138
+ async def test_oindex (data : st .DataObject ) -> None :
148
139
# integer_array_indices can't handle 0-size dimensions.
149
140
zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
150
141
nparray = zarray [:]
151
-
152
142
zindexer , npindexer = data .draw (orthogonal_indices (shape = nparray .shape ))
143
+
144
+ # sync get
153
145
actual = zarray .oindex [zindexer ]
154
146
assert_array_equal (nparray [npindexer ], actual )
155
147
148
+ # async get
149
+ async_zarray = zarray ._async_array
150
+ actual = await async_zarray .oindex .getitem (zindexer )
151
+ assert_array_equal (nparray [npindexer ], actual )
152
+
153
+ # sync get
156
154
assume (zarray .shards is None ) # GH2834
157
155
for idxr in npindexer :
158
156
if isinstance (idxr , np .ndarray ) and idxr .size != np .unique (idxr ).size :
@@ -163,38 +161,32 @@ def test_oindex(data: st.DataObject) -> None:
163
161
zarray .oindex [zindexer ] = new_data
164
162
assert_array_equal (nparray , zarray [:])
165
163
166
-
167
- @pytest .mark .asyncio
168
- @given (data = st .data ())
169
- @pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
170
- async def test_oindex_async (data : st .DataObject ) -> None :
171
- # integer_array_indices can't handle 0-size dimensions.
172
- zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
173
- nparray = zarray [:]
174
- async_zarray = zarray ._async_array
175
-
176
- zindexer , npindexer = data .draw (orthogonal_indices (shape = nparray .shape ))
177
- actual = await async_zarray .oindex .getitem (zindexer )
178
- assert_array_equal (nparray [npindexer ], actual )
179
-
180
- # note: async oindex setting not yet implemented
164
+ # note: async oindex setitem not yet implemented
181
165
182
166
167
+ @pytest .mark .asyncio
183
168
@given (data = st .data ())
184
169
@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
185
- def test_vindex (data : st .DataObject ) -> None :
170
+ async def test_vindex (data : st .DataObject ) -> None :
186
171
# integer_array_indices can't handle 0-size dimensions.
187
172
zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
188
173
nparray = zarray [:]
189
-
190
174
indexer = data .draw (
191
175
npst .integer_array_indices (
192
176
shape = nparray .shape , result_shape = npst .array_shapes (min_side = 1 , max_dims = None )
193
177
)
194
178
)
179
+
180
+ # sync get
195
181
actual = zarray .vindex [indexer ]
196
182
assert_array_equal (nparray [indexer ], actual )
197
183
184
+ # async get
185
+ async_zarray = zarray ._async_array
186
+ actual = await async_zarray .vindex .getitem (indexer )
187
+ assert_array_equal (nparray [indexer ], actual )
188
+
189
+ # sync set
198
190
# FIXME!
199
191
# when the indexer is such that a value gets overwritten multiple times,
200
192
# I think the output depends on chunking.
@@ -203,23 +195,7 @@ def test_vindex(data: st.DataObject) -> None:
203
195
# zarray.vindex[indexer] = new_data
204
196
# assert_array_equal(nparray, zarray[:])
205
197
206
-
207
- @pytest .mark .asyncio
208
- @given (data = st .data ())
209
- @pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
210
- async def test_vindex_async (data : st .DataObject ) -> None :
211
- # integer_array_indices can't handle 0-size dimensions.
212
- zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
213
- nparray = zarray [:]
214
- async_zarray = zarray ._async_array
215
-
216
- indexer = data .draw (
217
- npst .integer_array_indices (
218
- shape = nparray .shape , result_shape = npst .array_shapes (min_side = 1 , max_dims = None )
219
- )
220
- )
221
- actual = await async_zarray .vindex .getitem (indexer )
222
- assert_array_equal (nparray [indexer ], actual )
198
+ # note: async vindex setitem not yet implemented
223
199
224
200
225
201
@given (store = stores , meta = array_metadata ()) # type: ignore[misc]
0 commit comments