Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3e772c

Browse files
authored
Merge pull request #28774 from charris/backport-28750
TYP: fix `count_nonzero` signature
2 parents 29f6e15 + 9005fc1 commit b3e772c

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
@@ -110,6 +110,7 @@ from numpy._typing import (
110110
_ArrayLikeTD64_co,
111111
_ArrayLikeObject_co,
112112
_ArrayLikeUnknown,
113+
_NestedSequence,
113114
)
114115

115116
__all__ = [
@@ -456,21 +457,19 @@ def full_like(
456457
device: None | L["cpu"] = ...,
457458
) -> NDArray[Any]: ...
458459

460+
#
459461
@overload
460-
def count_nonzero(
461-
a: ArrayLike,
462-
axis: None = ...,
463-
*,
464-
keepdims: L[False] = ...,
465-
) -> int: ...
462+
def count_nonzero(a: ArrayLike, axis: None = None, *, keepdims: L[False] = False) -> int: ...
463+
@overload
464+
def count_nonzero(a: _ScalarLike_co, axis: _ShapeLike | None = None, *, keepdims: L[True]) -> np.intp: ...
466465
@overload
467466
def count_nonzero(
468-
a: ArrayLike,
469-
axis: _ShapeLike = ...,
470-
*,
471-
keepdims: bool = ...,
472-
) -> Any: ... # TODO: np.intp or ndarray[np.intp]
467+
a: NDArray[Any] | _NestedSequence[ArrayLike], axis: _ShapeLike | None = None, *, keepdims: L[True]
468+
) -> NDArray[np.intp]: ...
469+
@overload
470+
def count_nonzero(a: ArrayLike, axis: _ShapeLike | None = None, *, keepdims: bool = False) -> Any: ...
473471

472+
#
474473
def isfortran(a: NDArray[Any] | generic) -> bool: ...
475474

476475
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
@@ -31,7 +31,7 @@ C: SubClass
3131
assert_type(np.count_nonzero(i8), int)
3232
assert_type(np.count_nonzero(AR_i8), int)
3333
assert_type(np.count_nonzero(B), int)
34-
assert_type(np.count_nonzero(AR_i8, keepdims=True), Any)
34+
assert_type(np.count_nonzero(AR_i8, keepdims=True), npt.NDArray[np.intp])
3535
assert_type(np.count_nonzero(AR_i8, axis=0), Any)
3636

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

0 commit comments

Comments
 (0)