Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TYP: TypeMaskedArray.__{iadd,isub,imul,itruediv,ifloordiv,ipow}__#28986

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jorenham merged 9 commits intonumpy:mainfromMarcoGorelli:ma-inplace-ops
May 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
179 changes: 173 additions & 6 deletionsnumpy/ma/core.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,22 +17,40 @@ from numpy import (
amax,
amin,
bool_,
bytes_,
character,
complexfloating,
datetime64,
dtype,
dtypes,
expand_dims,
float64,
floating,
generic,
int_,
intp,
ndarray,
object_,
signedinteger,
str_,
timedelta64,
unsignedinteger,
)
from numpy._globals import _NoValueType
from numpy._typing import (
ArrayLike,
NDArray,
_ArrayLike,
_ArrayLikeBool_co,
_ArrayLikeBytes_co,
_ArrayLikeComplex_co,
_ArrayLikeFloat_co,
_ArrayLikeInt,
_ArrayLikeInt_co,
_ArrayLikeStr_co,
_ArrayLikeString_co,
_ArrayLikeTD64_co,
_ArrayLikeUInt_co,
_DTypeLikeBool,
_IntLike_co,
_ScalarLike_co,
Expand DownExpand Up@@ -456,12 +474,161 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
def __rfloordiv__(self, other): ...
def __pow__(self, other, mod: None = None, /): ...
def __rpow__(self, other, mod: None = None, /): ...
def __iadd__(self, other): ...
def __isub__(self, other): ...
def __imul__(self, other): ...
def __ifloordiv__(self, other): ...
def __itruediv__(self, other): ...
def __ipow__(self, other): ...

# Keep in sync with `ndarray.__iadd__`, except that `_MaskedArray[unsignedinteger]` does not accept
# _IntLike_co for `other`.
@overload
def __iadd__(
self: _MaskedArray[np.bool], other: _ArrayLikeBool_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: _MaskedArray[timedelta64 | datetime64], other: _ArrayLikeTD64_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(self: _MaskedArray[bytes_], other: _ArrayLikeBytes_co, /) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: MaskedArray[Any, dtype[str_] | dtypes.StringDType],
other: _ArrayLikeStr_co | _ArrayLikeString_co,
/,
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __iadd__(
self: _MaskedArray[object_], other: Any, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...

# Keep in sync with `ndarray.__isub__`, except that `_MaskedArray[unsignedinteger]` does not accept
# _IntLike_co for `other`.
@overload
def __isub__(
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __isub__(
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __isub__(
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __isub__(
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __isub__(
self: _MaskedArray[timedelta64 | datetime64], other: _ArrayLikeTD64_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __isub__(
self: _MaskedArray[object_], other: Any, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...

# Keep in sync with `ndarray.__imul__`, except that `_MaskedArray[unsignedinteger]` does not accept
# _IntLike_co for `other`.
@overload
def __imul__(
self: _MaskedArray[np.bool], other: _ArrayLikeBool_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __imul__(
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __imul__(
self: MaskedArray[Any, dtype[signedinteger] | dtype[character] | dtypes.StringDType],
other: _ArrayLikeInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __imul__(
self: _MaskedArray[floating | timedelta64], other: _ArrayLikeFloat_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __imul__(
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __imul__(
self: _MaskedArray[object_], other: Any, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...

# Keep in sync with `ndarray.__ifloordiv__`, except that `_MaskedArray[unsignedinteger]` does not accept
# _IntLike_co for `other`.
@overload
def __ifloordiv__(
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ifloordiv__(
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ifloordiv__(
self: _MaskedArray[floating | timedelta64], other: _ArrayLikeFloat_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ifloordiv__(
self: _MaskedArray[object_], other: Any, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...

# Keep in sync with `ndarray.__itruediv__`, except that `_MaskedArray[unsignedinteger]` does not accept
# _IntLike_co for `other`.
@overload
def __itruediv__(
self: _MaskedArray[floating | timedelta64], other: _ArrayLikeFloat_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __itruediv__(
self: _MaskedArray[complexfloating],
other: _ArrayLikeComplex_co,
/,
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __itruediv__(
self: _MaskedArray[object_], other: Any, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...

# Keep in sync with `ndarray.__ipow__`, except that `_MaskedArray[unsignedinteger]` does not accept
# _IntLike_co for `other`.
@overload
def __ipow__(
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ipow__(
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ipow__(
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ipow__(
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
@overload
def __ipow__(
self: _MaskedArray[object_], other: Any, /
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...

#
@property # type: ignore[misc]
def imag(self: _HasDTypeWithRealAndImag[object, _ScalarT], /) -> MaskedArray[_ShapeT_co, dtype[_ScalarT]]: ...
get_imag: Any
Expand Down
13 changes: 13 additions & 0 deletionsnumpy/typing/tests/data/fail/ma.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
from typing import TypeAlias, TypeVar

import numpy as np
import numpy.typing as npt
from numpy._typing import _Shape

_ScalarT = TypeVar("_ScalarT", bound=np.generic)
MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT]]

MAR_1d_f8: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
MAR_b: MaskedArray[np.bool]
MAR_c: MaskedArray[np.complex128]
MAR_td64: MaskedArray[np.timedelta64]

AR_b: npt.NDArray[np.bool]

Expand DownExpand Up@@ -127,4 +136,8 @@ np.ma.allclose(MAR_1d_f8, [1,2,3], atol='.5') # type: ignore[arg-type]

MAR_1d_f8.__setmask__('mask') # type: ignore[arg-type]

MAR_b *= 2 # type: ignore[arg-type]
MAR_c //= 2 # type: ignore[misc]
MAR_td64 **= 2 # type: ignore[misc]

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

[8]ページ先頭

©2009-2025 Movatter.jp