8000 TYP: Type ``MaskedArray.nonzero`` · numpy/numpy@df3c5f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit df3c5f0

Browse files
committed
TYP: Type MaskedArray.nonzero
1 parent 4690af9 commit df3c5f0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

numpy/ma/core.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
492492
def iscontiguous(self) -> bool: ...
493493
def all(self, axis=..., out=..., keepdims=...): ...
494494
def any(self, axis=..., out=..., keepdims=...): ...
495-
def nonzero(self): ...
495+
def nonzero(self) -> tuple[_Array1D[intp], *tuple[_Array1D[intp], ...]]: ...
496496
def trace(self, offset=..., axis1=..., axis2=..., dtype=..., out=...): ...
497497
def dot(self, b, out=..., strict=...): ...
498498
def sum(self, axis=..., dtype=..., out=..., keepdims=...): ...

numpy/typing/tests/data/reveal/ma.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from numpy._typing import NDArray, _Shape
77

88
_ScalarT = TypeVar("_ScalarT", bound=generic)
99
MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, dtype[_ScalarT]]
10+
_Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarT]]
1011

1112
class MaskedArraySubclass(MaskedArray[np.complex128]): ...
1213

@@ -314,3 +315,6 @@ assert_type(MAR_2d_f4.swapaxes(1, 0), MaskedArray[np.float32])
314315
assert_type(np.ma.nomask, np.bool[Literal[False]])
315316
# https://github.com/python/mypy/issues/18974
316317
assert_type(np.ma.MaskType, type[np.bool]) # type: ignore[assert-type]
318+
319+
assert_type(MAR_2d_f4.nonzero(), tuple[_Array1D[np.intp], *tuple[_Array1D[np.intp], ...]])
320+
assert_type(MAR_2d_f4.nonzero()[0], _Array1D[np.intp])

0 commit comments

Comments
 (0)
0