Skip to content

Commit 5eacdb0

Browse files
committed
support async orthogonal indexing via zarr-developers/zarr-python#3083
1 parent 82c7654 commit 5eacdb0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

xarray/backends/zarr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ async def _async_getitem(self, key):
218218
async_array = self._array._async_array
219219
return await async_array.getitem(key)
220220

221+
async def _async_oindex(self, key):
222+
async_array = self._array._async_array
223+
return await async_array.oindex.getitem(key)
224+
221225
def __getitem__(self, key):
222226
array = self._array
223227
if isinstance(key, indexing.BasicIndexer):
@@ -241,12 +245,11 @@ async def async_getitem(self, key):
241245
# method = self._vindex
242246
raise NotImplementedError("async lazy vectorized indexing is not supported")
243247
elif isinstance(key, indexing.OuterIndexer):
244-
# method = self._oindex
245-
raise NotImplementedError("async lazy orthogonal indexing is not supported")
248+
method = self._async_oindex
246249

247250
print("did an async get")
248251
return await indexing.async_explicit_indexing_adapter(
249-
key, array.shape, indexing.IndexingSupport.BASIC, method
252+
key, array.shape, indexing.IndexingSupport.OUTER, method
250253
)
251254

252255

xarray/tests/test_async.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class LatencyStore(WrapperStore[T_Store]):
2525

2626
latency: float
2727

28+
# TODO only have to add this because of dumb behaviour in zarr where it raises with "ValueError: Store is not read-only but mode is 'r'"
29+
read_only = True
30+
2831
def __init__(
2932
self,
3033
store: T_Store,
@@ -175,7 +178,6 @@ async def test_concurrent_load_multiple_objects(self, xr_obj) -> None:
175178
total_time=timer.total_time, latency=self.LATENCY, n_loads=N_OBJECTS
176179
)
177180

178-
@pytest.mark.xfail(reason="not implemented")
179181
async def test_indexing(self, memorystore) -> None:
180182
latencystore = LatencyStore(memorystore, latency=self.LATENCY)
181183
ds = xr.open_zarr(latencystore, zarr_format=3, consolidated=False, chunks=None)

0 commit comments

Comments
 (0)