11import json
22import numbers
33from typing import Any
4+ import asyncio
45
56import numpy as np
67import pytest
@@ -121,6 +122,26 @@ def test_basic_indexing(data: st.DataObject) -> None:
121122 assert_array_equal (nparray , zarray [:])
122123
123124
125+ @settings (deadline = None )
126+ @pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
127+ @given (data = st .data ())
128+ 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 = asyncio .run (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)
143+
144+
124145@given (data = st .data ())
125146@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
126147def test_oindex (data : st .DataObject ) -> None :
@@ -143,6 +164,21 @@ def test_oindex(data: st.DataObject) -> None:
143164 assert_array_equal (nparray , zarray [:])
144165
145166
167+ @given (data = st .data ())
168+ @pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
169+ def test_oindex_async (data : st .DataObject ) -> None :
170+ # integer_array_indices can't handle 0-size dimensions.
171+ zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
172+ nparray = zarray [:]
173+ async_zarray = zarray ._async_array
174+
175+ zindexer , npindexer = data .draw (orthogonal_indices (shape = nparray .shape ))
176+ actual = asyncio .run (async_zarray .oindex .getitem (zindexer ))
177+ assert_array_equal (nparray [npindexer ], actual )
178+
179+ # note: async oindex setting not yet implemented
180+
181+
146182@given (data = st .data ())
147183@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
148184def test_vindex (data : st .DataObject ) -> None :
@@ -167,6 +203,23 @@ def test_vindex(data: st.DataObject) -> None:
167203 # assert_array_equal(nparray, zarray[:])
168204
169205
206+ @given (data = st .data ())
207+ @pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
208+ def test_vindex_async (data : st .DataObject ) -> None :
209+ # integer_array_indices can't handle 0-size dimensions.
210+ zarray = data .draw (simple_arrays (shapes = npst .array_shapes (max_dims = 4 , min_side = 1 )))
211+ nparray = zarray [:]
212+ async_zarray = zarray ._async_array
213+
214+ indexer = data .draw (
215+ npst .integer_array_indices (
216+ shape = nparray .shape , result_shape = npst .array_shapes (min_side = 1 , max_dims = None )
217+ )
218+ )
219+ actual = asyncio .run (async_zarray .vindex .getitem (indexer ))
220+ assert_array_equal (nparray [indexer ], actual )
221+
222+
170223@given (store = stores , meta = array_metadata ()) # type: ignore[misc]
171224@pytest .mark .filterwarnings ("ignore::zarr.core.dtype.common.UnstableSpecificationWarning" )
172225async def test_roundtrip_array_metadata_from_store (
0 commit comments