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
Prev Previous commit
Next Next commit
avoid silencing overload overlap
  • Loading branch information
MarcoGorelli committed Apr 16, 2025
commit b067ef5acc647493f0ccd472f0a2739a80bb0b22
8 changes: 6 additions & 2 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,13 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):

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

def ravel(self, order=...): ...
def reshape(self, *s, **kwargs): ...
Expand Down
3 changes: 3 additions & 0 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ 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=None), 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(MAR_o.count(axis=None, keepdims=True), NDArray[np.int_])
assert_type(MAR_o.count(None, True), NDArray[np.int_])

assert_type(np.ma.count(MAR_byte), int)
assert_type(np.ma.count(MAR_f4, axis=0), NDArray[np.int_])
Expand Down
Loading
0