@@ -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
@@ -1527,7 +1537,7 @@ def is_fancy_indexer(indexer: Any) -> bool:
1527
1537
return True
1528
1538
1529
1539
1530
- class NumpyIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1540
+ class NumpyIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1531
1541
"""Wrap a NumPy array to use explicit indexing."""
1532
1542
1533
1543
__slots__ = ("array" ,)
@@ -1606,7 +1616,7 @@ def __init__(self, array):
1606
1616
self .array = array
1607
1617
1608
1618
1609
- class ArrayApiIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1619
+ class ArrayApiIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1610
1620
"""Wrap an array API array to use explicit indexing."""
1611
1621
1612
1622
__slots__ = ("array" ,)
@@ -1671,7 +1681,7 @@ def _assert_not_chunked_indexer(idxr: tuple[Any, ...]) -> None:
1671
1681
)
1672
1682
1673
1683
1674
- class DaskIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1684
+ class DaskIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1675
1685
"""Wrap a dask array to support explicit indexing."""
1676
1686
1677
1687
__slots__ = ("array" ,)
@@ -1747,7 +1757,7 @@ def transpose(self, order):
1747
1757
return self .array .transpose (order )
1748
1758
1749
1759
1750
- class PandasIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1760
+ class PandasIndexingAdapter (IndexingAdapter , ExplicitlyIndexedNDArrayMixin ):
1751
1761
"""Wrap a pandas.Index to preserve dtypes and handle explicit indexing."""
1752
1762
1753
1763
__slots__ = ("_dtype" , "array" )
@@ -2068,7 +2078,9 @@ def copy(self, deep: bool = True) -> Self:
2068
2078
return type (self )(array , self ._dtype , self .level )
2069
2079
2070
2080
2071
- class CoordinateTransformIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
2081
+ class CoordinateTransformIndexingAdapter (
2082
+ IndexingAdapter , ExplicitlyIndexedNDArrayMixin
2083
+ ):
2072
2084
"""Wrap a CoordinateTransform as a lazy coordinate array.
2073
2085
2074
2086
Supports explicit indexing (both outer and vectorized).
0 commit comments