8000 TYP: Type ``MaskedArray.{__setmask__,mask,harden_mask,soften_mask,hardmask,unshare_mask,sharedmask,shrink_mask}`` by MarcoGorelli · Pull Request #28867 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Type MaskedArray.{__setmask__,mask,harden_mask,soften_mask,hardmask,unshare_mask,sharedmask,shrink_mask} #28867

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 4 commits into from
May 3, 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
import Self from typing, use MaskType, move test to pass/ma.py
  • Loading branch information
MarcoGorelli committed May 1, 2025
commit 7e5ff6d4d9bd51937b7d7e46ccbf0691b0dc949e
8 changes: 4 additions & 4 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# ruff: noqa: ANN001, ANN002, ANN003, ANN201, ANN202 ANN204, ANN401

from collections.abc import Sequence
from typing import Any, Literal, SupportsIndex, TypeAlias, TypeVar, overload
from typing import Any, Literal, Self, SupportsIndex, TypeAlias, TypeVar, overload

from _typeshed import Incomplete
from typing_extensions import Self, TypeIs, deprecated
from typing_extensions import TypeIs, deprecated

import numpy as np
from numpy import (
Expand Down Expand Up @@ -410,9 +410,9 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
def shape(self: MaskedArray[_ShapeT, Any], shape: _ShapeT, /) -> None: ...
def __setmask__(self, mask: _ArrayLikeBool_co, copy: bool = False) -> None: ...
@property
def mask(self) -> NDArray[bool_] | MaskType: ...
def mask(self) -> NDArray[MaskType] | MaskType: ...
@mask.setter
def mask(self, value: _ArrayLikeBool_co) -> None: ...
def mask(self, value: _ArrayLikeBool_co, /) -> None: ...
@property
def recordmask(self): ...
@recordmask.setter
Expand Down
6 changes: 5 additions & 1 deletion numpy/typing/tests/data/pass/ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import numpy as np
import numpy.ma
import numpy.typing as npt


ar_b: npt.NDArray[np.bool] = np.array([True, False, True])
m: np.ma.MaskedArray[Any, np.dtype[np.float64]] = np.ma.masked_array([1.5, 2, 3], mask=[True, False, True])

m.mask = ar_b
m.mask = np.False_

4 changes: 0 additions & 4 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,6 @@ assert_type(np.ma.MaskType, type[np.bool]) # type: ignore[assert-type]
assert_type(MAR_1d.__setmask__([True, False]), None)
assert_type(MAR_1d.__setmask__(np.False_), None)

# Test setters - just check these don't raise
MAR_1d.mask = AR_b
MAR_1d.mask = np.False_

assert_type(MAR_2d_f4.harden_mask(), np.ma.MaskedArray[tuple[int, int], np.dtype[np.float32]])
assert_type(MAR_i8.harden_mask(), MaskedArray[np.int64])
assert_type(MAR_2d_f4.soften_mask(), np.ma.MaskedArray[tuple[int, int], np.dtype[np.float32]])
Expand Down
0