MCPcopy Index your code
hub / github.com/pydata/xarray / CustomArrayIndexable

Class CustomArrayIndexable

xarray/tests/test_namedarray.py:69–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67
68
69class CustomArrayIndexable(
70 CustomArrayBase[_ShapeType_co, _DType_co],
71 ExplicitlyIndexed,
72 Generic[_ShapeType_co, _DType_co],
73):
74 def __getitem__(
75 self, key: _IndexKeyLike | CustomArrayIndexable[Any, Any], /
76 ) -> CustomArrayIndexable[Any, _DType_co]:
77 if isinstance(key, CustomArrayIndexable):
78 if isinstance(key.array, type(self.array)):
79 # TODO: key.array is duckarray here, can it be narrowed down further?
80 # an _arrayapi cannot be used on a _arrayfunction for example.
81 return type(self)(array=self.array[key.array]) # type: ignore[index]
82 else:
83 raise TypeError("key must have the same array type as self")
84 else:
85 return type(self)(array=self.array[key])
86
87 def __array_namespace__(self) -> ModuleType:
88 return np
89
90
91def check_duck_array_typevar(a: duckarray[Any, _DType]) -> duckarray[Any, _DType]:

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…