@@ -520,8 +520,7 @@ class ExplicitlyIndexedNDArrayMixin(NDArrayMixin, ExplicitlyIndexed):
520520 __slots__ = ()
521521
522522 def get_duck_array (self ):
523- key = BasicIndexer ((slice (None ),) * self .ndim )
524- return self [key ]
523+ raise NotImplementedError
525524
526525 def _oindex_get (self , indexer : OuterIndexer ):
527526 raise NotImplementedError (
@@ -559,6 +558,17 @@ def vindex(self) -> IndexCallable:
559558 return IndexCallable (self ._vindex_get , self ._vindex_set )
560559
561560
561+ class IndexingAdapter :
562+ """Marker class for indexing adapters.
563+ These classes translate between Xarray's indexing semantics and the underlying array's
564+ indexing semantics.
565+ """
566+
567+ def get_duck_array (self ):
568+ key = BasicIndexer ((slice (None ),) * self .ndim )
569+ return self [key ]
570+
571+
562572class ImplicitToExplicitIndexingAdapter (NDArrayMixin ):
563573 """Wrap an array, converting tuples into the indicated explicit indexer."""
564574
@@ -1527,7 +1537,7 @@ def is_fancy_indexer(indexer: Any) -> bool:
15271537 return True
15281538
15291539
1530- class NumpyIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1540+ class NumpyIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
15311541 """Wrap a NumPy array to use explicit indexing."""
15321542
15331543 __slots__ = ("array" ,)
@@ -1606,7 +1616,7 @@ def __init__(self, array):
16061616 self .array = array
16071617
16081618
1609- class ArrayApiIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1619+ class ArrayApiIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
16101620 """Wrap an array API array to use explicit indexing."""
16111621
16121622 __slots__ = ("array" ,)
@@ -1671,7 +1681,7 @@ def _assert_not_chunked_indexer(idxr: tuple[Any, ...]) -> None:
16711681 )
16721682
16731683
1674- class DaskIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1684+ class DaskIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
16751685 """Wrap a dask array to support explicit indexing."""
16761686
16771687 __slots__ = ("array" ,)
@@ -1747,7 +1757,7 @@ def transpose(self, order):
17471757 return self .array .transpose (order )
17481758
17491759
1750- class PandasIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1760+ class PandasIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
17511761 """Wrap a pandas.Index to preserve dtypes and handle explicit indexing."""
17521762
17531763 __slots__ = ("_dtype" , "array" )
@@ -2068,7 +2078,9 @@ def copy(self, deep: bool = True) -> Self:
20682078 return type (self )(array , self ._dtype , self .level )
20692079
20702080
2071- class CoordinateTransformIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
2081+ class CoordinateTransformIndexingAdapter (
2082+ IndexingAdapter , ExplicitlyIndexedNDArrayMixin
2083+ ):
20722084 """Wrap a CoordinateTransform as a lazy coordinate array.
20732085
20742086 Supports explicit indexing (both outer and vectorized).
0 commit comments