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

Method _validate_indexers

xarray/core/variable.py:697–731  ·  view source on GitHub ↗

Make sanity checks

(self, key)

Source from the content-addressed store, hash-verified

695 return dims, BasicIndexer(key), None
696
697 def _validate_indexers(self, key):
698 """Make sanity checks"""
699 for dim, k in zip(self.dims, key, strict=True):
700 if not isinstance(k, BASIC_INDEXING_TYPES):
701 if not isinstance(k, Variable):
702 if not is_duck_array(k):
703 k = np.asarray(k)
704 if k.ndim > 1:
705 raise IndexError(
706 "Unlabeled multi-dimensional array cannot be "
707 f"used for indexing: {k}"
708 )
709 if k.dtype.kind == "b":
710 if self.shape[self.get_axis_num(dim)] != len(k):
711 raise IndexError(
712 f"Boolean array size {len(k):d} is used to index array "
713 f"with shape {self.shape}."
714 )
715 if k.ndim > 1:
716 raise IndexError(
717 f"{k.ndim}-dimensional boolean indexing is not supported. "
718 )
719 if is_duck_dask_array(k.data):
720 raise KeyError(
721 "Indexing with a boolean dask array is not allowed. "
722 "This will result in a dask array of unknown shape. "
723 "Such arrays are unsupported by Xarray."
724 "Please compute the indexer first using .compute()"
725 )
726 if getattr(k, "dims", (dim,)) != (dim,):
727 raise IndexError(
728 "Boolean indexer should be unlabeled or on the "
729 "same dimension to the indexed array. Indexer is "
730 f"on {k.dims} but the target dimension is {dim}."
731 )
732
733 def _broadcast_indexes_outer(self, key):
734 # drop dim if k is integer or if k is a 0d dask array

Callers 1

_broadcast_indexesMethod · 0.95

Calls 3

is_duck_arrayFunction · 0.90
is_duck_dask_arrayFunction · 0.90
get_axis_numMethod · 0.45

Tested by

no test coverage detected