Skip to content

Commit a43af86

Browse files
committed
IndexingAdapters don't need async get
1 parent 884ce13 commit a43af86

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

xarray/core/indexing.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,9 @@ async def async_get_duck_array(self):
678678
# and self.key is BasicIndexer((slice(None, None, None),))
679679
# so we need the explicit check for ExplicitlyIndexed
680680
if isinstance(array, ExplicitlyIndexed):
681-
array = await array.async_get_duck_array()
681+
# At this point, we have issued completed the possible async load from disk
682+
# and array is in-memory. So use the sync get
683+
array = array.get_duck_array()
682684
return _wrap_numpy_scalars(array)
683685

684686
def transpose(self, order):
@@ -769,7 +771,9 @@ async def async_get_duck_array(self):
769771
# and self.key is BasicIndexer((slice(None, None, None),))
770772
# so we need the explicit check for ExplicitlyIndexed
771773
if isinstance(array, ExplicitlyIndexed):
772-
array = await array.async_get_duck_array()
774+
# At this point, we have issued completed the possible async load from disk
775+
# and array is in-memory. So use the sync get
776+
array = array.get_duck_array()
773777
return _wrap_numpy_scalars(array)
774778

775779
def _updated_key(self, new_key: ExplicitIndexer):
@@ -877,15 +881,16 @@ def __init__(self, array):
877881
self.array = _wrap_numpy_scalars(as_indexable(array))
878882

879883
def get_duck_array(self):
880-
# first ensure the array object is cached
881-
self.array = as_indexable(self.array.get_duck_array())
882-
return self.array.get_duck_array()
884+
duck_array = self.array.get_duck_array()
885+
# ensure the array object is cached in-memory
886+
self.array = as_indexable(duck_array)
887+
return duck_array
883888

884889
async def async_get_duck_array(self):
885-
# first ensure the array object is cached
886890
duck_array = await self.array.async_get_duck_array()
891+
# ensure the array object is cached in-memory
887892
self.array = as_indexable(duck_array)
888-
return await self.array.async_get_duck_array()
893+
return duck_array
889894

890895
def _oindex_get(self, indexer: OuterIndexer):
891896
return type(self)(_wrap_numpy_scalars(self.array.oindex[indexer]))
@@ -1620,16 +1625,6 @@ def __getitem__(self, indexer: ExplicitIndexer):
16201625
key = indexer.tuple + (Ellipsis,)
16211626
return array[key]
16221627

1623-
async def async_getitem(self, indexer: ExplicitIndexer):
1624-
self._check_and_raise_if_non_basic_indexer(indexer)
1625-
1626-
array = self.array
1627-
# We want 0d slices rather than scalars. This is achieved by
1628-
# appending an ellipsis (see
1629-
# https://numpy.org/doc/stable/reference/arrays.indexing.html#detailed-notes).
1630-
key = indexer.tuple + (Ellipsis,)
1631-
return array[key]
1632-
16331628
def _safe_setitem(self, array, key: tuple[Any, ...], value: Any) -> None:
16341629
try:
16351630
array[key] = value

0 commit comments

Comments
 (0)