8000 Merge pull request #28750 from jorenham/typing/count_nonzero · numpy/numpy@b59d8ce · GitHub
[go: up one dir, main page]

Skip to content

Commit b59d8ce

Browse files
authored
Merge pull request #28750 from jorenham/typing/count_nonzero
TYP: fix `count_nonzero` signature
2 parents 4ede17d + a9cb2bb commit b59d8ce

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

numpy/_core/numeric.pyi

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ from numpy._typing import (
9898
_ArrayLikeComplex_co,
9999
_ArrayLikeTD64_co,
100100
_ArrayLikeObject_co,
101+
_NestedSequence,
101102
)
102103

103104
__all__ = [
@@ -413,21 +414,19 @@ def full_like(
413414
device: None | L["cpu"] = ...,
414415
) -> NDArray[Any]: ...
415416

417+
#
416418
@overload
417-
def count_nonzero(
418-
a: ArrayLike,
419-
axis: None = ...,
420-
*,
421-
keepdims: L[False] = ...,
422-
) -> int: ...
419+
def count_nonzero(a: ArrayLike, axis: None = None, *, keepdims: L[False] = False) -> int: ...
420+
@overload
421+
def count_nonzero(a: _ScalarLike_co, axis: _ShapeLike | None = None, *, keepdims: L[True]) -> np.intp: ...
423422
@overload
424423
def count_nonzero(
425-
a: ArrayLike,
426-
axis: _ShapeLike = ...,
427-
*,
428-
keepdims: bool = ...,
429-
) -> Any: ... # TODO: np.intp or ndarray[np.intp]
424+
a: NDArray[Any] | _NestedSequence[ArrayLike], axis: _ShapeLike | None = None, *, keepdims: L[True]
425+
) -> NDArray[np.intp]: ...
426+
@overload
427+
def count_nonzero(a: ArrayLike, axis: _ShapeLike | None = None, *, keepdims: bool = False) -> Any: ...
430428

429+
#
431430
def isfortran(a: NDArray[Any] | generic) -> bool: ...
432431

433432
def argwhere(a: ArrayLike) -> NDArray[intp]: ...

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ C: SubClass
2828
assert_type(np.count_nonzero(i8), int)
2929
assert_type(np.count_nonzero(AR_i8), int)
3030
assert_type(np.count_nonzero(B), int)
31-
assert_type(np.count_nonzero(AR_i8, keepdims=True), Any)
31+
assert_type(np.count_nonzero(AR_i8, keepdims=True), npt.NDArray[np.intp])
3232
assert_type(np.count_nonzero(AR_i8, axis=0), Any)
3333

3434
assert_type(np.isfortran(i8), bool)

0 commit comments

Comments
 (0)
0