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

Skip to content

TYP: Type np.ma.getmask #28832

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 26, 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
overload getmask
  • Loading branch information
MarcoGorelli committed Apr 26, 2025
commit d1c6afadc87cfa0643826b80863e715bc275115a
5 changes: 5 additions & 0 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ mod: _DomainedBinaryOperation

def make_mask_descr(ndtype): ...

@overload
def getmask(a: _ScalarLike_co) -> bool_: ...
@overload
def getmask(a: MaskedArray[_ShapeT_co, Any]) -> np.ndarray[_ShapeT_co, dtype[bool_]] | bool_: ...
@overload
def getmask(a: ArrayLike) -> NDArray[bool_] | bool_: ...

get_mask = getmask
Expand Down
7 changes: 5 additions & 2 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ assert_type(np.ma.allclose(AR_f4, MAR_f4, masked_equal=False), bool)
assert_type(np.ma.allclose(AR_f4, MAR_f4, rtol=.4, atol=.3), bool)

assert_type(np.ma.getmask(MAR_f4), NDArray[np.bool] | np.bool)
assert_type(np.ma.getmask(MAR_1d), NDArray[np.bool] | np.bool)
assert_type(np.ma.getmask(MAR_2d_f4), NDArray[np.bool] | np.bool)
# PyRight detects this one correctly, but mypy doesn't:
# `Revealed type is "Union[numpy.ndarray[Any, Any], numpy.bool[Any]]"`
assert_type(np.ma.getmask(MAR_1d), np.ndarray[tuple[int], np.dtype[np.bool]] | np.bool) # type: ignore[assert-type]
assert_type(np.ma.getmask(MAR_2d_f4), np.ndarray[tuple[int, int], np.dtype[np.bool]] | np.bool)
assert_type(np.ma.getmask([1,2]), NDArray[np.bool] | np.bool)
assert_type(np.ma.getmask(np.int64(1)), np.bool)
Loading
0