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

Commit06dc6b3

Browse files
committed
TYP: TypeMaskedArray.__{iadd,isub,imul,itruediv,ifloordiv,pow}__
1 parent4e628f4 commit06dc6b3

File tree

3 files changed

+387
-39
lines changed

3 files changed

+387
-39
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
fromnumpy._globalsimport_NoValueType
2937
fromnumpy._typingimport (
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
defimag(self:_HasDTypeWithRealAndImag[object,_ScalarT],/)->MaskedArray[_ShapeT_co,dtype[_ScalarT]]: ...
467637
get_imag:Any

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

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
fromtypingimportTypeAlias,TypeVar
2+
13
importnumpyasnp
24
importnumpy.typingasnpt
5+
fromnumpyimportdtype,generic
6+
fromnumpy._typingimport_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

@@ -68,13 +78,13 @@ MAR_1d_f8.any(axis=1.0) # type: ignore[call-overload]
6878
MAR_1d_f8.any(keepdims=1.0)# type: ignore[call-overload]
6979
MAR_1d_f8.any(out=1.0)# type: ignore[call-overload]
7080

71-
MAR_1d_f8.sort(axis=(0,1))# type: ignore[arg-type]
81+
MAR_1d_f8.sort(axis=(0,1))# type: ignore[arg-type]
7282
MAR_1d_f8.sort(axis=None)# type: ignore[arg-type]
73-
MAR_1d_f8.sort(kind='cabbage')# type: ignore[arg-type]
74-
MAR_1d_f8.sort(order=lambda:'cabbage')# type: ignore[arg-type]
75-
MAR_1d_f8.sort(endwith='cabbage')# type: ignore[arg-type]
76-
MAR_1d_f8.sort(fill_value=lambda:'cabbage')# type: ignore[arg-type]
77-
MAR_1d_f8.sort(stable='cabbage')# type: ignore[arg-type]
83+
MAR_1d_f8.sort(kind="cabbage")# type: ignore[arg-type]
84+
MAR_1d_f8.sort(order=lambda:"cabbage")# type: ignore[arg-type]
85+
MAR_1d_f8.sort(endwith="cabbage")# type: ignore[arg-type]
86+
MAR_1d_f8.sort(fill_value=lambda:"cabbage")# type: ignore[arg-type]
87+
MAR_1d_f8.sort(stable="cabbage")# type: ignore[arg-type]
7888
MAR_1d_f8.sort(stable=True)# type: ignore[arg-type]
7989

8090
MAR_1d_f8.take(axis=1.0)# type: ignore[call-overload]
@@ -86,45 +96,57 @@ np.ma.take(axis=1.0) # type: ignore[call-overload]
8696
np.ma.take(out=1)# type: ignore[call-overload]
8797
np.ma.take(mode="bob")# type: ignore[call-overload]
8898

89-
MAR_1d_f8.partition(['cabbage'])# type: ignore[arg-type]
90-
MAR_1d_f8.partition(axis=(0,1))# type: ignore[arg-type, call-arg]
91-
MAR_1d_f8.partition(kind='cabbage')# type: ignore[arg-type, call-arg]
92-
MAR_1d_f8.partition(order=lambda:'cabbage')# type: ignore[arg-type, call-arg]
99+
MAR_1d_f8.partition(["cabbage"])# type: ignore[arg-type]
100+
MAR_1d_f8.partition(axis=(0,1))# type: ignore[arg-type, call-arg]
101+
MAR_1d_f8.partition(kind="cabbage")# type: ignore[arg-type, call-arg]
102+
MAR_1d_f8.partition(order=lambda:"cabbage")# type: ignore[arg-type, call-arg]
93103
MAR_1d_f8.partition(AR_b)# type: ignore[arg-type]
94104

95-
MAR_1d_f8.argpartition(['cabbage'])# type: ignore[arg-type]
96-
MAR_1d_f8.argpartition(axis=(0,1))# type: ignore[arg-type, call-arg]
97-
MAR_1d_f8.argpartition(kind='cabbage')# type: ignore[arg-type, call-arg]
98-
MAR_1d_f8.argpartition(order=lambda:'cabbage')# type: ignore[arg-type, call-arg]
105+
MAR_1d_f8.argpartition(["cabbage"])# type: ignore[arg-type]
106+
MAR_1d_f8.argpartition(axis=(0,1))# type: ignore[arg-type, call-arg]
107+
MAR_1d_f8.argpartition(kind="cabbage")# type: ignore[arg-type, call-arg]
108+
MAR_1d_f8.argpartition(order=lambda:"cabbage")# type: ignore[arg-type, call-arg]
99109
MAR_1d_f8.argpartition(AR_b)# type: ignore[arg-type]
100110

101-
np.ma.ndim(lambda:'lambda')# type: ignore[arg-type]
111+
np.ma.ndim(lambda:"lambda")# type: ignore[arg-type]
112+
113+
np.ma.size(AR_b,axis="0")# type: ignore[arg-type]
114+
115+
MAR_1d_f8>= (lambdax:"mango")# type: ignore[operator]
116+
MAR_1d_f8> (lambdax:"mango")# type: ignore[operator]
117+
MAR_1d_f8<= (lambdax:"mango")# type: ignore[operator]
118+
MAR_1d_f8< (lambdax:"mango")# type: ignore[operator]
119+
120+
MAR_1d_f8.count(axis=0.0)# type: ignore[call-overload]
121+
122+
np.ma.count(MAR_1d_f8,axis=0.0)# type: ignore[call-overload]
102123

103-
np.ma.size(AR_b,axis='0')# type: ignore[arg-type]
124+
MAR_1d_f8.put(4,999,mode="flip")# type: ignore[arg-type]
104125

105-
MAR_1d_f8>= (lambdax:'mango')# type: ignore[operator]
106-
MAR_1d_f8> (lambdax:'mango')# type: ignore[operator]
107-
MAR_1d_f8<= (lambdax:'mango')# type: ignore[operator]
108-
MAR_1d_f8< (lambdax:'mango')# type: ignore[operator]
126+
np.ma.put(MAR_1d_f8,4,999,mode="flip")# type: ignore[arg-type]
109127

110-
MAR_1d_f8.count(axis=0.)# type: ignore[call-overload]
128+
np.ma.put([1,1,3],0,999)# type: ignore[arg-type]
111129

112-
np.ma.count(MAR_1d_f8,axis=0.)# type: ignore[call-overload]
130+
np.ma.compressed(lambda:"compress me")# type: ignore[call-overload]
113131

114-
MAR_1d_f8.put(4,999,mode='flip')# type: ignore[arg-type]
132+
np.ma.allequal(MAR_1d_f8, [1,2,3],fill_value=1.5)# type: ignore[arg-type]
115133

116-
np.ma.put(MAR_1d_f8,4,999,mode='flip')# type: ignore[arg-type]
134+
np.ma.allclose(MAR_1d_f8, [1,2,3],masked_equal=4.5)# type: ignore[arg-type]
135+
np.ma.allclose(MAR_1d_f8, [1,2,3],rtol=".4")# type: ignore[arg-type]
136+
np.ma.allclose(MAR_1d_f8, [1,2,3],atol=".5")# type: ignore[arg-type]
117137

118-
np.ma.put([1,1,3],0,999)# type: ignore[arg-type]
138+
MAR_1d_f8.__setmask__("mask")# type: ignore[arg-type]
119139

120-
np.ma.compressed(lambda:'compress me')# type: ignore[call-overload]
140+
np.ma.allequal(MAR_1d_f8, [1,2,3],fill_value=1.5)# type: ignore[arg-type]
121141

122-
np.ma.allequal(MAR_1d_f8, [1,2,3],fill_value=1.5)# type: ignore[arg-type]
142+
np.ma.allclose(MAR_1d_f8, [1,2,3],masked_equal=4.5)# type: ignore[arg-type]
143+
np.ma.allclose(MAR_1d_f8, [1,2,3],rtol=".4")# type: ignore[arg-type]
144+
np.ma.allclose(MAR_1d_f8, [1,2,3],atol=".5")# type: ignore[arg-type]
123145

124-
np.ma.allclose(MAR_1d_f8, [1,2,3],masked_equal=4.5)# type: ignore[arg-type]
125-
np.ma.allclose(MAR_1d_f8, [1,2,3],rtol='.4')# type: ignore[arg-type]
126-
np.ma.allclose(MAR_1d_f8, [1,2,3],atol='.5')# type: ignore[arg-type]
146+
MAR_1d_f8.__setmask__("mask")# type: ignore[arg-type]
127147

128-
MAR_1d_f8.__setmask__('mask')# type: ignore[arg-type]
148+
MAR_b*=2# type: ignore[arg-type]
149+
MAR_c//=2# type: ignore[misc]
150+
MAR_td64**=2# type: ignore[misc]
129151

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp