@@ -105,54 +105,52 @@ def test_array_creates_implicit_groups(array):
105105# this decorator removes timeout; not ideal but it should avoid intermittent CI failures
106106
107107
108+ @pytest .mark .asyncio
108109@settings (deadline = None )
109110@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
110111@given (data = st .data ())
111- def test_basic_indexing (data : st .DataObject ) -> None :
112+ async def test_basic_indexing (data : st .DataObject ) -> None :
112113 zarray = data .draw (simple_arrays ())
113114 nparray = zarray [:]
114115 indexer = data .draw (basic_indices (shape = nparray .shape ))
116+
117+ # sync get
115118 actual = zarray [indexer ]
116119 assert_array_equal (nparray [indexer ], actual )
117120
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
118127 new_data = data .draw (numpy_arrays (shapes = st .just (actual .shape ), dtype = nparray .dtype ))
119128 zarray [indexer ] = new_data
120129 nparray [indexer ] = new_data
121130 assert_array_equal (nparray , zarray [:])
122131
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?
143133
144134
135+ @pytest .mark .asyncio
145136@given (data = st .data ())
146137@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 :
148139 # integer_array_indices can't handle 0-size dimensions.
149140 zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
150141 nparray = zarray [:]
151-
152142 zindexer , npindexer = data .draw (orthogonal_indices (shape = nparray .shape ))
143+
144+ # sync get
153145 actual = zarray .oindex [zindexer ]
154146 assert_array_equal (nparray [npindexer ], actual )
155147
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
156154 assume (zarray .shards is None ) # GH2834
157155 for idxr in npindexer :
158156 if isinstance (idxr , np .ndarray ) and idxr .size != np .unique (idxr ).size :
@@ -163,38 +161,32 @@ def test_oindex(data: st.DataObject) -> None:
163161 zarray .oindex [zindexer ] = new_data
164162 assert_array_equal (nparray , zarray [:])
165163
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
181165
182166
167+ @pytest .mark .asyncio
183168@given (data = st .data ())
184169@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 :
186171 # integer_array_indices can't handle 0-size dimensions.
187172 zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
188173 nparray = zarray [:]
189-
190174 indexer = data .draw (
191175 npst .integer_array_indices (
192176 shape = nparray .shape , result_shape = npst .array_shapes (min_side = 1 , max_dims = None )
193177 )
194178 )
179+
180+ # sync get
195181 actual = zarray .vindex [indexer ]
196182 assert_array_equal (nparray [indexer ], actual )
197183
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
198190 # FIXME!
199191 # when the indexer is such that a value gets overwritten multiple times,
200192 # I think the output depends on chunking.
@@ -203,23 +195,7 @@ def test_vindex(data: st.DataObject) -> None:
203195 # zarray.vindex[indexer] = new_data
204196 # assert_array_equal(nparray, zarray[:])
205197
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
223199
224200
225201@given (store = stores , meta = array_metadata ()) # type: ignore[misc]
0 commit comments