Skip to content

TYP: Type MaskedArray.__deepcopy__ and MaskedArray.argsort #29418

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
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ class _ArrayOrScalarCommon:
order: str | Sequence[str] | None = ...,
*,
stable: bool | None = ...,
) -> NDArray[Any]: ...
) -> NDArray[intp]: ...

@overload # axis=None (default), out=None (default), keepdims=False (default)
def argmax(self, /, axis: None = None, out: None = None, *, keepdims: L[False] = False) -> intp: ...
Expand Down
2 changes: 1 addition & 1 deletion numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5628,7 +5628,7 @@ def argsort(self, axis=np._NoValue, kind=None, order=None, endwith=True,
is used.
kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
The sorting algorithm used.
order : list, optional
order : str or list of str, optional
When `a` is an array with fields defined, this argument specifies
which fields to compare first, second, etc. Not all fields need be
specified.
Expand Down
13 changes: 11 additions & 2 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,16 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
@overload
def round(self, /, decimals: SupportsIndex = 0, *, out: _ArrayT) -> _ArrayT: ...

def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
def argsort(
self,
axis: SupportsIndex | _NoValueType = ...,
kind: _SortKind | None = None,
order: str | Sequence[str] | None = None,
endwith: bool = True,
fill_value: _ScalarLike_co | None = None,
*,
stable: bool = False,
) -> _MaskedArray[intp]: ...

# Keep in-sync with np.ma.argmin
@overload # type: ignore[override]
Expand Down Expand Up @@ -1703,7 +1712,7 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):

#
def __reduce__(self): ...
def __deepcopy__(self, memo=...): ...
def __deepcopy__(self, memo: dict[int, Any] | None = None) -> Self: ...

# Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
@property
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 @@ -141,3 +141,5 @@ MAR_c //= 2 # type: ignore[misc]
MAR_td64 **= 2 # type: ignore[misc]

MAR_1d_f8.swapaxes(axis1=1, axis2=0) # type: ignore[call-arg]

MAR_1d_f8.argsort(axis=(1,0)) # type: ignore[arg-type]
6 changes: 6 additions & 0 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ assert_type(MAR_f8.cumprod(out=MAR_subclass), MaskedArraySubclass)
assert_type(MAR_f8.cumsum(), MaskedArray[Any])
assert_type(MAR_f8.cumsum(out=MAR_subclass), MaskedArraySubclass)

assert_type(MAR_f8.__deepcopy__(), MaskedArray[np.float64])

assert_type(MAR_f8.argsort(), MaskedArray[np.intp])
assert_type(MAR_f8.argsort(axis=0, kind='heap', order=('x', 'y')), MaskedArray[np.intp])
assert_type(MAR_f8.argsort(endwith=True, fill_value=1.5, stable=False), MaskedArray[np.intp])

def invalid_resize() -> None:
assert_type(MAR_f8.resize((1,1)), NoReturn) # type: ignore[arg-type]

Expand Down
4 changes: 2 additions & 2 deletions numpy/typing/tests/data/reveal/ndarray_misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ assert_type(AR_f8.argmin(), np.intp)
assert_type(AR_f8.argmin(axis=0), Any)
assert_type(AR_f8.argmin(out=AR_i8), npt.NDArray[np.intp])

assert_type(f8.argsort(), npt.NDArray[Any])
assert_type(AR_f8.argsort(), npt.NDArray[Any])
assert_type(f8.argsort(), npt.NDArray[np.intp])
assert_type(AR_f8.argsort(), npt.NDArray[np.intp])

assert_type(f8.astype(np.int64).choose([()]), npt.NDArray[Any])
assert_type(AR_f8.choose([0]), npt.NDArray[Any])
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy