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

Method __init__

xarray/core/indexing.py:562–591  ·  view source on GitHub ↗
(self, key: tuple[slice | np.ndarray[Any, np.dtype[np.generic]], ...])

Source from the content-addressed store, hash-verified

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

nothing calls this directly

Calls 5

is_duck_arrayFunction · 0.90
as_integer_sliceFunction · 0.85
typeFunction · 0.85
astypeMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected