MCPcopy
hub / github.com/pydata/xarray / ImplicitToExplicitIndexingAdapter

Class ImplicitToExplicitIndexingAdapter

xarray/core/indexing.py:673–704  ·  view source on GitHub ↗

Wrap an array, converting tuples into the indicated explicit indexer.

Source from the content-addressed store, hash-verified

671
672
673class ImplicitToExplicitIndexingAdapter(NDArrayMixin):
674 """Wrap an array, converting tuples into the indicated explicit indexer."""
675
676 __slots__ = ("array", "indexer_cls")
677
678 def __init__(self, array, indexer_cls: type[ExplicitIndexer] = BasicIndexer):
679 self.array = as_indexable(array)
680 self.indexer_cls = indexer_cls
681
682 def __array__(
683 self, dtype: DTypeLike | None = None, /, *, copy: bool | None = None
684 ) -> np.ndarray:
685 if Version(np.__version__) >= Version("2.0.0"):
686 return np.asarray(self.get_duck_array(), dtype=dtype, copy=copy)
687 else:
688 return np.asarray(self.get_duck_array(), dtype=dtype)
689
690 def get_duck_array(self):
691 return self.array.get_duck_array()
692
693 def __getitem__(self, key: Any):
694 key = expanded_indexer(key, self.ndim)
695 indexer = self.indexer_cls(key)
696
697 result = apply_indexer(self.array, indexer)
698
699 if isinstance(result, ExplicitlyIndexed):
700 return type(self)(result, self.indexer_cls)
701 else:
702 # Sometimes explicitly indexed arrays return NumPy arrays or
703 # scalars.
704 return result
705
706
707class LazilyIndexedArray(ExplicitlyIndexedNDArrayMixin):

Callers 1

chunkMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…