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

Class VectorizedIndexer

xarray/core/indexing.py:550–591  ·  view source on GitHub ↗

Tuple for vectorized indexing. All elements should be slice or N-dimensional np.ndarray objects with an integer dtype and the same number of dimensions. Indexing follows proposed rules for np.ndarray.vindex, which matches NumPy's advanced indexing rules (including broadcasting) exce

Source from the content-addressed store, hash-verified

548
549
550class VectorizedIndexer(ExplicitIndexer):
551 """Tuple for vectorized indexing.
552
553 All elements should be slice or N-dimensional np.ndarray objects with an
554 integer dtype and the same number of dimensions. Indexing follows proposed
555 rules for np.ndarray.vindex, which matches NumPy's advanced indexing rules
556 (including broadcasting) except sliced axes are always moved to the end:
557 https://github.com/numpy/numpy/pull/6256
558 """
559
560 __slots__ = ()
561
562 def __init__(self, key: tuple[slice | np.ndarray[Any, np.dtype[np.generic]], ...]):
563 if not isinstance(key, tuple):
564 raise TypeError(f"key must be a tuple: {key!r}")
565
566 new_key = []
567 ndim = None
568 for k in key:
569 if isinstance(k, slice):
570 k = as_integer_slice(k)
571 elif is_duck_array(k):
572 if not np.issubdtype(k.dtype, np.integer):
573 raise TypeError(
574 f"invalid indexer array, does not have integer dtype: {k!r}"
575 )
576 if ndim is None:
577 ndim = k.ndim # type: ignore[union-attr]
578 elif ndim != k.ndim: # type: ignore[union-attr]
579 ndims = [k.ndim for k in key if isinstance(k, np.ndarray)]
580 raise ValueError(
581 "invalid indexer key: ndarray arguments "
582 f"have different numbers of dimensions: {ndims}"
583 )
584 k = duck_array_ops.astype(k, np.int64, copy=False)
585 else:
586 raise TypeError(
587 f"unexpected indexer type for {type(self).__name__}: {k!r}"
588 )
589 new_key.append(k)
590
591 super().__init__(tuple(new_key))
592
593
594class ExplicitlyIndexed:

Callers 8

transposeMethod · 0.90
_combine_indexersFunction · 0.90
_vindex_getMethod · 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…