8000 TYP: Type ``MaskedArray.count`` and ``np.ma.count`` by MarcoGorelli · Pull Request #28735 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Type MaskedArray.count and np.ma.count #28735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TYP: Type MaskedArray.count and np.ma.count
  • Loading branch information
MarcoGorelli committed Apr 16, 2025
commit 4f4f449bd6ec9bfdba0e1655d04c6963dbd6ecc5
15 changes: 13 additions & 2 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ from numpy import (
expand_dims,
float64,
generic,
int_,
intp,
ndarray,
)
Expand Down Expand Up @@ -452,7 +453,13 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
@property # type: ignore[misc]
def real(self): ...
get_real: Any
def count(self, axis=..., keepdims=...): ...

# keep in sync with `np.ma.count`
@overload
def count(self, axis: None = None, keepdims: Literal[False] | _NoValueType = ...) -> int: ... # type: ignore[overload-overlap]
@overload
def count(self, axis: _ShapeLike | None = None, keepdims: bool | _NoValueType = ...) -> NDArray[int_]: ...

def ravel(self, order=...): ...
def reshape(self, *s, **kwargs): ...
def resize(self, newshape, refcheck=..., order=...): ...
Expand Down Expand Up @@ -949,7 +956,11 @@ sum: _frommethod
swapaxes: _frommethod
trace: _frommethod
var: _frommethod
count: _frommethod

@overload
def count(self: ArrayLike, axis: None = None, keepdims: Literal[False] | _NoValueType = ...) -> int: ...
@overload
def count(self: ArrayLike, axis: _ShapeLike | None = None, keepdims: bool | _NoValueType = ...) -> NDArray[int_]: ...

@overload
def argmin(
Expand Down
4 changes: 4 additions & 0 deletions numpy/typing/tests/data/fail/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ m > (lambda x: 'mango') # E: No overload variant
m <= (lambda x: 'mango') # E: No overload variant

m < (lambda x: 'mango') # E: No overload variant

m.count(axis=0.) # E: No overload variant

np.ma.count(m, axis=0.) # E: No overload variant
9 changes: 9 additions & 0 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,12 @@ assert_type(MAR_1d <= 0, MaskedNDArray[np.bool])
assert_type(MAR_s <= MAR_s, MaskedNDArray[np.bool])
assert_type(MAR_byte <= MAR_byte, MaskedNDArray[np.bool])

assert_type(MAR_byte.count(), int)
assert_type(MAR_f4.count(axis=0), NDArray[np.int_])
assert_type(MAR_b.count(axis=(0,1)), NDArray[np.int_])
assert_type(MAR_o.count(keepdims=True), NDArray[np.int_])

assert_type(np.ma.count(MAR_byte), int)
assert_type(np.ma.count(MAR_f4, axis=0), NDArray[np.int_])
assert_type(np.ma.count(MAR_b, axis=(0,1)), NDArray[np.int_])
assert_type(np.ma.count(MAR_o, keepdims=True), NDArray[np.int_])
Loading
0