@@ -520,8 +520,7 @@ class ExplicitlyIndexedNDArrayMixin(NDArrayMixin, ExplicitlyIndexed):
520
520
__slots__ = ()
521
521
522
522
def get_duck_array (self ):
523
- key = BasicIndexer ((slice (None ),) * self .ndim )
524
- return self [key ]
523
+ raise NotImplementedError
525
524
526
525
def _oindex_get (self , indexer : OuterIndexer ):
527
526
raise NotImplementedError (
@@ -559,6 +558,17 @@ def vindex(self) -> IndexCallable:
559
558
return IndexCallable (self ._vindex_get , self ._vindex_set )
560
559
561
560
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
+
562
572
class ImplicitToExplicitIndexingAdapter (NDArrayMixin ):
563
573
"""Wrap an array, converting tuples into the indicated explicit indexer."""
564
574
@@ -1526,7 +1536,7 @@ def is_fancy_indexer(indexer: Any) -> bool:
1526
1536
return True
1527
1537
1528
1538
1529
- class NumpyIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1539
+ class NumpyIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1530
1540
"""Wrap a NumPy array to use explicit indexing."""
1531
1541
1532
1542
__slots__ = ("array" ,)
@@ -1605,7 +1615,7 @@ def __init__(self, array):
1605
1615
self .array = array
1606
1616
1607
1617
1608
- class ArrayApiIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1618
+ class ArrayApiIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1609
1619
"""Wrap an array API array to use explicit indexing."""
1610
1620
1611
1621
__slots__ = ("array" ,)
@@ -1670,7 +1680,7 @@ def _assert_not_chunked_indexer(idxr: tuple[Any, ...]) -> None:
1670
1680
)
1671
1681
1672
1682
1673
- class DaskIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1683
+ class DaskIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1674
1684
"""Wrap a dask array to support explicit indexing."""
1675
1685
1676
1686
__slots__ = ("array" ,)
@@ -1746,7 +1756,7 @@ def transpose(self, order):
1746
1756
return self .array .transpose (order )
1747
1757
1748
1758
1749
- class PandasIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1759
+ class PandasIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1750
1760
"""Wrap a pandas.Index to preserve dtypes and handle explicit indexing."""
1751
1761
1752
1762
__slots__ = ("_dtype" , "array" )
@@ -2063,7 +2073,9 @@ def copy(self, deep: bool = True) -> Self:
2063
2073
return type (self )(array , self ._dtype , self .level )
2064
2074
2065
2075
2066
- class CoordinateTransformIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
2076
+ class CoordinateTransformIndexingAdapter (
2077
+ IndexingAdapter , ExplicitlyIndexedNDArrayMixin
2078
+ ):
2067
2079
"""Wrap a CoordinateTransform as a lazy coordinate array.
2068
2080
2069
2081
Supports explicit indexing (both outer and vectorized).
0 commit comments