@@ -516,6 +516,20 @@ def get_duck_array(self):
516
516
return self .array
517
517
518
518
519
+ class IndexingAdapter :
520
+ """Marker class for indexing adapters.
521
+
522
+ These classes translate between Xarray's indexing semantics and the underlying array's
523
+ indexing semantics.
524
+ """
525
+
526
+ async def async_get_duck_array ():
527
+ """These classes are applied to in-memory arrays, so async get isn't needed."""
528
+ raise RuntimeError (
529
+ f"{ type (self ).__name__ } async_get_duck_array was called. This should not happen."
530
+ )
531
+
532
+
519
533
class ExplicitlyIndexedNDArrayMixin (NDArrayMixin , ExplicitlyIndexed ):
520
534
__slots__ = ()
521
535
@@ -1589,7 +1603,7 @@ def is_fancy_indexer(indexer: Any) -> bool:
1589
1603
return True
1590
1604
1591
1605
1592
- class NumpyIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1606
+ class NumpyIndexingAdapter (ExplicitlyIndexedNDArrayMixin , IndexingAdapter ):
1593
1607
"""Wrap a NumPy array to use explicit indexing."""
1594
1608
1595
1609
__slots__ = ("array" ,)
@@ -1668,7 +1682,7 @@ def __init__(self, array):
1668
1682
self .array = array
1669
1683
1670
1684
1671
- class ArrayApiIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1685
+ class ArrayApiIndexingAdapter (ExplicitlyIndexedNDArrayMixin , IndexingAdapter ):
1672
1686
"""Wrap an array API array to use explicit indexing."""
1673
1687
1674
1688
__slots__ = ("array" ,)
@@ -1733,7 +1747,7 @@ def _assert_not_chunked_indexer(idxr: tuple[Any, ...]) -> None:
1733
1747
)
1734
1748
1735
1749
1736
- class DaskIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1750
+ class DaskIndexingAdapter (ExplicitlyIndexedNDArrayMixin , IndexingAdapter ):
1737
1751
"""Wrap a dask array to support explicit indexing."""
1738
1752
1739
1753
__slots__ = ("array" ,)
@@ -1809,7 +1823,7 @@ def transpose(self, order):
1809
1823
return self .array .transpose (order )
1810
1824
1811
1825
1812
- class PandasIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
1826
+ class PandasIndexingAdapter (ExplicitlyIndexedNDArrayMixin , IndexingAdapter ):
1813
1827
"""Wrap a pandas.Index to preserve dtypes and handle explicit indexing."""
1814
1828
1815
1829
__slots__ = ("_dtype" , "array" )
@@ -2135,7 +2149,9 @@ def copy(self, deep: bool = True) -> Self:
2135
2149
return type (self )(array , self ._dtype , self .level )
2136
2150
2137
2151
2138
- class CoordinateTransformIndexingAdapter (ExplicitlyIndexedNDArrayMixin ):
2152
+ class CoordinateTransformIndexingAdapter (
2153
+ ExplicitlyIndexedNDArrayMixin , IndexingAdapter
2154
+ ):
2139
2155
"""Wrap a CoordinateTransform as a lazy coordinate array.
2140
2156
2141
2157
Supports explicit indexing (both outer and vectorized).
0 commit comments