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

Method _nonzero

xarray/namedarray/core.py:949–959  ·  view source on GitHub ↗

Equivalent numpy's nonzero but returns a tuple of NamedArrays.

(self: T_NamedArrayInteger)

Source from the content-addressed store, hash-verified

947 return from_array(dims, data, attrs=self._attrs)
948
949 def _nonzero(self: T_NamedArrayInteger) -> tuple[T_NamedArrayInteger, ...]:
950 """Equivalent numpy's nonzero but returns a tuple of NamedArrays."""
951 # TODO: we should replace dask's native nonzero
952 # after https://github.com/dask/dask/issues/1076 is implemented.
953 # TODO: cast to ndarray and back to T_DuckArray is a workaround
954 nonzeros = np.nonzero(cast("NDArray[np.integer[Any]]", self.data))
955 _attrs = self.attrs
956 return tuple(
957 cast("T_NamedArrayInteger", self._new((dim,), nz, _attrs))
958 for nz, dim in zip(nonzeros, self.dims, strict=True)
959 )
960
961 def __repr__(self) -> str:
962 return formatting.array_repr(self)

Callers 1

Calls 1

_newMethod · 0.95

Tested by

no test coverage detected