Skip to content

Commit 71b1258

Browse files
committed
TYP: Type MaskedArray.__{iadd,isub,imul,itruediv,ifloordiv,pow}__
1 parent 3e68b26 commit 71b1258

File tree

3 files changed

+348
-8
lines changed

3 files changed

+348
-8
lines changed

numpy/ma/core.pyi

Lines changed: 176 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,34 @@ from numpy import (
1717
amax,
1818
amin,
1919
bool_,
20+
complex128,
21+
complexfloating,
22+
datetime64,
2023
dtype,
2124
expand_dims,
2225
float64,
26+
floating,
2327
generic,
2428
int_,
2529
intp,
2630
ndarray,
31+
object_,
32+
signedinteger,
33+
timedelta64,
34+
unsignedinteger,
2735
)
2836
from numpy._globals import _NoValueType
2937
from numpy._typing import (
3038
ArrayLike,
3139
NDArray,
3240
_ArrayLike,
3341
_ArrayLikeBool_co,
42+
_ArrayLikeComplex_co,
43+
_ArrayLikeFloat_co,
3444
_ArrayLikeInt,
3545
_ArrayLikeInt_co,
46+
_ArrayLikeTD64_co,
47+
_ArrayLikeUInt_co,
3648
_DTypeLikeBool,
3749
_IntLike_co,
3850
_ScalarLike_co,
@@ -456,12 +468,170 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
456468
def __rfloordiv__(self, other): ...
457469
def __pow__(self, other, mod: None = None, /): ...
458470
def __rpow__(self, other, mod: None = None, /): ...
459-
def __iadd__(self, other): ...
460-
def __isub__(self, other): ...
461-
def __imul__(self, other): ...
462-
def __ifloordiv__(self, other): ...
463-
def __itruediv__(self, other): ...
464-
def __ipow__(self, other): ...
471+
472+
# Keep in sync with `ndarray.__iadd__`, except that `_MaskedArray[unsignedinteger]` does not accept
473+
# _IntLake_co for `other`.
474+
@overload
475+
def __iadd__(
476+
self: _MaskedArray[np.bool], other: _ArrayLikeBool_co, /
477+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
478+
@overload
479+
def __iadd__(
480+
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
481+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
482+
@overload
483+
def __iadd__(
484+
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
485+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
486+
@overload
487+
def __iadd__(
488+
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
489+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
490+
@overload
491+
def __iadd__(
492+
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
493+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
494+
@overload
495+
def __iadd__(
496+
self: _MaskedArray[timedelta64 | datetime64], other: _ArrayLikeTD64_co, /
497+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
498+
@overload
499+
def __iadd__(
500+
self: _MaskedArray[object_], other: Any, /
501+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
502+
503+
# Keep in sync with `ndarray.__isub__`, except that `_MaskedArray[unsignedinteger]` does not accept
504+
# _IntLike_co for `other`.
505+
@overload
506+
def __isub__(
507+
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
508+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
509+
@overload
510+
def __isub__(
511+
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
512+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
513+
@overload
514+
def __isub__(
515+
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
516+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
517+
@overload
518+
def __isub__(
519+
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
520+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
521+
@overload
522+
def __isub__(
523+
self: _MaskedArray[timedelta64 | datetime64], other: _ArrayLikeTD64_co, /
524+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
525+
@overload
526+
def __isub__(
527+
self: _MaskedArray[object_], other: Any, /
528+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
529+
530+
# Keep in sync with `ndarray.__imul__`, except that `_MaskedArray[unsignedinteger]` does not accept
531+
# _IntLike_co for `other`.
532+
@overload
533+
def __imul__(
534+
self: _MaskedArray[np.bool], other: _ArrayLikeBool_co, /
535+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
536+
@overload
537+
def __imul__(
538+
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
539+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
540+
@overload
541+
def __imul__(
542+
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
543+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
544+
@overload
545+
def __imul__(
546+
self: _MaskedArray[float64], other: _ArrayLikeFloat_co, /
547+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
548+
@overload
549+
def __imul__(
550+
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
551+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
552+
@overload
553+
def __imul__(
554+
self: _MaskedArray[complex128], other: _ArrayLikeComplex_co, /
555+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
556+
@overload
557+
def __imul__(
558+
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
559+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
560+
@overload
561+
def __imul__(
562+
self: _MaskedArray[timedelta64], other: _ArrayLikeFloat_co, /
563+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
564+
@overload
565+
def __imul__(
566+
self: _MaskedArray[object_], other: Any, /
567+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
568+
569+
# Keep in sync with `ndarray.__ifloordiv__`, except that `_MaskedArray[unsignedinteger]` does not accept
570+
# _IntLike_co for `other`.
571+
@overload
572+
def __ifloordiv__(
573+
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
574+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
575+
@overload
576+
def __ifloordiv__(
577+
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
578+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
579+
@overload
580+
def __ifloordiv__(
581+
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
582+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
583+
@overload
584+
def __ifloordiv__(
585+
self: _MaskedArray[timedelta64], other: _ArrayLikeInt, /
586+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
587+
@overload
588+
def __ifloordiv__(
589+
self: _MaskedArray[object_], other: Any, /
590+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
591+
592+
# Keep in sync with `ndarray.__itruediv__`, except that `_MaskedArray[unsignedinteger]` does not accept
593+
# _IntLike_co for `other`.
594+
@overload
595+
def __itruediv__(
596+
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
597+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
598+
@overload
599+
def __itruediv__(
600+
self: _MaskedArray[complexfloating],
601+
other: _ArrayLikeComplex_co,
602+
/,
603+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
604+
@overload
605+
def __itruediv__(
606+
self: _MaskedArray[timedelta64], other: _ArrayLikeInt, /
607+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
608+
@overload
609+
def __itruediv__(
610+
self: _MaskedArray[object_], other: Any, /
611+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
612+
613+
# Keep in sync with `ndarray.__ipow__`, except that `_MaskedArray[unsignedinteger]` does not accept
614+
# _IntLike_co for `other`.
615+
@overload
616+
def __ipow__(
617+
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
618+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
619+
@overload
620+
def __ipow__(
621+
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
622+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
623+
@overload
624+
def __ipow__(
625+
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
626+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
627+
@overload
628+
def __ipow__(
629+
self: _MaskedArray[complexfloating], other: _ArrayLikeComplex_co, /
630+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
631+
@overload
632+
def __ipow__(
633+
self: _MaskedArray[object_], other: Any, /
634+
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
465635
@property # type: ignore[misc]
466636
def imag(self: _HasDTypeWithRealAndImag[object, _ScalarT], /) -> MaskedArray[_ShapeT_co, dtype[_ScalarT]]: ...
467637
get_imag: Any

numpy/typing/tests/data/fail/ma.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
from typing import TypeAlias, TypeVar
2+
13
import numpy as np
24
import numpy.typing as npt
5+
from numpy import dtype, generic
6+
from numpy._typing import _Shape
7+
8+
_ScalarT = TypeVar("_ScalarT", bound=generic)
9+
MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, dtype[_ScalarT]]
310

411
MAR_1d_f8: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]
12+
MAR_b: MaskedArray[np.bool]
13+
MAR_c: MaskedArray[np.complex128]
14+
MAR_td64: MaskedArray[np.timedelta64]
515

616
AR_b: npt.NDArray[np.bool]
717

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

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

140+
MAR_b *= 2 # type: ignore[arg-type]
141+
MAR_c //= 2 # type: ignore[misc]
142+
MAR_td64 **= 2 # type: ignore[misc]
143+
130144
MAR_1d_f8.swapaxes(axis1=1, axis2=0) # type: ignore[call-arg]

0 commit comments

Comments
 (0)
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