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

Method __init__

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

Source from the content-addressed store, hash-verified

515 __slots__ = ()
516
517 def __init__(
518 self,
519 key: tuple[BasicIndexerType | np.ndarray[Any, np.dtype[np.generic]], ...],
520 ):
521 if not isinstance(key, tuple):
522 raise TypeError(f"key must be a tuple: {key!r}")
523
524 new_key = []
525 for k in key:
526 if isinstance(k, integer_types) and not isinstance(k, bool):
527 k = int(k)
528 elif isinstance(k, slice):
529 k = as_integer_slice(k)
530 elif is_duck_array(k):
531 if not np.issubdtype(k.dtype, np.integer):
532 raise TypeError(
533 f"invalid indexer array, does not have integer dtype: {k!r}"
534 )
535 if k.ndim > 1: # type: ignore[union-attr]
536 raise TypeError(
537 f"invalid indexer array for {type(self).__name__}; must be scalar "
538 f"or have 1 dimension: {k!r}"
539 )
540 k = duck_array_ops.astype(k, np.int64, copy=False)
541 else:
542 raise TypeError(
543 f"unexpected indexer type for {type(self).__name__}: {k!r}, {type(k)}"
544 )
545 new_key.append(k)
546
547 super().__init__(tuple(new_key))
548
549
550class VectorizedIndexer(ExplicitIndexer):

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