Content-Length: 428172 | pFad | http://github.com/numpy/numpy/pull/28867/files/7e9df637a43d9b2d8583c837c0492aa9929de948

38 TYP: Type ``MaskedArray.{__setmask__,mask,harden_mask,soften_mask,hardmask,unshare_mask,sharedmask,shrink_mask}`` by MarcoGorelli · Pull Request #28867 · numpy/numpy · GitHub
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 3 commits
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
3 changes: 2 additions & 1 deletion numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3737,7 +3737,8 @@ def shrink_mask(self):

Returns
-------
None
result : MaskedArray
A :class:`~ma.MaskedArray` object.

Examples
--------
Expand Down
20 changes: 10 additions & 10 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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 TypeIs, deprecated
Expand Down Expand Up @@ -408,23 +408,23 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
def shape(self) -> _ShapeT_co: ...
@shape.setter
def shape(self: MaskedArray[_ShapeT, Any], shape: _ShapeT, /) -> None: ...
def __setmask__(self, mask, copy=...): ...
def __setmask__(self, mask: _ArrayLikeBool_co, copy: bool = False) -> None: ...
@property
def mask(self): ...
def mask(self) -> NDArray[MaskType] | MaskType: ...
@mask.setter
def mask(self, value): ...
def mask(self, value: _ArrayLikeBool_co, /) -> None: ...
@property
def recordmask(self): ...
@recordmask.setter
def recordmask(self, mask): ...
def harden_mask(self): ...
def soften_mask(self): ...
def harden_mask(self) -> Self: ...
def soften_mask(self) -> Self: ...
@property
def hardmask(self): ...
def unshare_mask(self): ...
def hardmask(self) -> bool: ...
def unshare_mask(self) -> Self: ...
@property
def sharedmask(self): ...
def shrink_mask(self): ...
def sharedmask(self) -> bool: ...
def shrink_mask(self) -> Self: ...
@property
def baseclass(self): ...
data: Any
Expand Down
2 changes: 2 additions & 0 deletions numpy/typing/tests/data/fail/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@ np.ma.allclose(m, [1,2,3], masked_equal=4.5) # E: No overload variant
np.ma.allclose(m, [1,2,3], rtol='.4') # E: No overload variant
np.ma.allclose(m, [1,2,3], atol='.5') # E: No overload variant

m.__setmask__('mask') # E: No overload variant

m.swapaxes(axis1=1, axis2=0) # E: No overload variant
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_

14 changes: 14 additions & 0 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ assert_type(np.ma.put(MAR_f4, 4, 999), None)
assert_type(np.ma.put(MAR_f4, 4, 999, mode='clip'), None)

assert_type(np.ma.putmask(MAR_f4, [True, False], [0, 1]), None)
assert_type(np.ma.putmask(MAR_f4, np.False_, [0, 1]), None)

assert_type(MAR_f4.filled(float('nan')), NDArray[np.float32])
assert_type(MAR_i8.filled(), NDArray[np.int64])
Expand Down Expand Up @@ -314,3 +315,16 @@ assert_type(MAR_2d_f4.swapaxes(1, 0), MaskedArray[np.float32])
assert_type(np.ma.nomask, np.bool[Literal[False]])
# https://github.com/python/mypy/issues/18974
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)

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]])
assert_type(MAR_i8.soften_mask(), MaskedArray[np.int64])
assert_type(MAR_f4.unshare_mask(), MaskedArray[np.float32])
assert_type(MAR_b.shrink_mask(), MaskedArray[np.bool_])

assert_type(MAR_i8.hardmask, bool)
assert_type(MAR_i8.sharedmask, bool)
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/numpy/numpy/pull/28867/files/7e9df637a43d9b2d8583c837c0492aa9929de948

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy