Equivalent numpy's nonzero but returns a tuple of NamedArrays.
(self: T_NamedArrayInteger)
| 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) |
no test coverage detected