Skip to content
forked from pydata/xarray

Commit

Permalink
Handle Indexing Adapter classes explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Jan 17, 2023
1 parent 9b727e6 commit 46d98ec
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ def shape(self) -> tuple[int, ...]:
def get_duck_array(self):
array = as_indexable(self.array)
array = array[self.key]
array = array.get_duck_array()
if not isinstance(self.array, IndexingAdapter):
array = array.get_duck_array()
return array

def transpose(self, order):
Expand Down Expand Up @@ -1238,7 +1239,11 @@ def is_fancy_indexer(indexer: Any) -> bool:
return True


class NumpyIndexingAdapter(ExplicitlyIndexedNDArrayMixin):
class IndexingAdapter:
pass


class NumpyIndexingAdapter(ExplicitlyIndexedNDArrayMixin, IndexingAdapter):
"""Wrap a NumPy array to use explicit indexing."""

__slots__ = ("array",)
Expand Down Expand Up @@ -1304,7 +1309,7 @@ def __init__(self, array):
self.array = array


class ArrayApiIndexingAdapter(ExplicitlyIndexedNDArrayMixin):
class ArrayApiIndexingAdapter(ExplicitlyIndexedNDArrayMixin, IndexingAdapter):
"""Wrap an array API array to use explicit indexing."""

__slots__ = ("array",)
Expand Down Expand Up @@ -1347,7 +1352,7 @@ def transpose(self, order):
return xp.permute_dims(self.array, order)


class DaskIndexingAdapter(ExplicitlyIndexedNDArrayMixin):
class DaskIndexingAdapter(ExplicitlyIndexedNDArrayMixin, IndexingAdapter):
"""Wrap a dask array to support explicit indexing."""

__slots__ = ("array",)
Expand Down Expand Up @@ -1423,7 +1428,7 @@ def transpose(self, order):
return self.array.transpose(order)


class PandasIndexingAdapter(ExplicitlyIndexedNDArrayMixin):
class PandasIndexingAdapter(ExplicitlyIndexedNDArrayMixin, IndexingAdapter):
"""Wrap a pandas.Index to preserve dtypes and handle explicit indexing."""

__slots__ = ("array", "_dtype")
Expand Down

0 comments on commit 46d98ec

Please sign in to comment.