@@ -1760,11 +1760,15 @@ _DType = TypeVar("_DType", bound=dtype[Any])
1760
1760
_DType_co = TypeVar ("_DType_co" , covariant = True , bound = dtype [Any ])
1761
1761
_FlexDType = TypeVar ("_FlexDType" , bound = dtype [flexible ])
1762
1762
1763
+ _IntegralArrayT = TypeVar ("_IntegralArrayT" , bound = NDArray [integer [Any ] | np .bool | object_ ])
1764
+ _RealArrayT = TypeVar ("_RealArrayT" , bound = NDArray [floating [Any ] | integer [Any ] | timedelta64 | np .bool | object_ ])
1765
+ _NumericArrayT = TypeVar ("_NumericArrayT" , bound = NDArray [number [Any ] | timedelta64 | object_ ])
1766
+
1763
1767
_Shape1D : TypeAlias = tuple [int ]
1764
1768
_Shape2D : TypeAlias = tuple [int , int ]
1765
1769
1770
+ _ShapeType = TypeVar ("_ShapeType" , bound = _Shape )
1766
1771
_ShapeType_co = TypeVar ("_ShapeType_co" , covariant = True , bound = _Shape )
1767
- _ShapeType2 = TypeVar ("_ShapeType2" , bound = _Shape )
1768
1772
_Shape2DType_co = TypeVar ("_Shape2DType_co" , covariant = True , bound = _Shape2D )
1769
1773
_NumberType = TypeVar ("_NumberType" , bound = number [Any ])
1770
1774
@@ -1881,11 +1885,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
1881
1885
1882
1886
def __array_wrap__ (
1883
1887
self ,
1884
- array : ndarray [_ShapeType2 , _DType ],
1888
+ array : ndarray [_ShapeType , _DType ],
1885
1889
context : None | tuple [ufunc , tuple [Any , ...], int ] = ...,
1886
1890
return_scalar : builtins .bool = ...,
1887
1891
/ ,
1888
- ) -> ndarray [_ShapeType2 , _DType ]: ...
1892
+ ) -> ndarray [_ShapeType , _DType ]: ...
1889
1893
1890
1894
@overload
1891
1895
def __getitem__ (self , key : (
@@ -2237,22 +2241,10 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2237
2241
offset : SupportsIndex = ...
2238
2242
) -> NDArray [Any ]: ...
2239
2243
2240
- # Dispatch to the underlying `generic` via protocols
2241
- def __int__ (
2242
- self : NDArray [SupportsInt ], # type: ignore[type-var]
2243
- ) -> int : ...
2244
-
2245
- def __float__ (
2246
- self : NDArray [SupportsFloat ], # type: ignore[type-var]
2247
- ) -> float : ...
2248
-
2249
- def __complex__ (
2250
- self : NDArray [SupportsComplex ], # type: ignore[type-var]
2251
- ) -> complex : ...
2252
-
2253
- def __index__ (
2254
- self : NDArray [SupportsIndex ], # type: ignore[type-var]
2255
- ) -> int : ...
2244
+ def __index__ (self : NDArray [np .integer [Any ]], / ) -> int : ...
2245
+ def __int__ (self : NDArray [number [Any ] | np .bool | object_ ], / ) -> int : ...
2246
+ def __float__ (self : NDArray [number [Any ] | np .bool | object_ ], / ) -> float : ...
2247
+ def __complex__ (self : NDArray [number [Any ] | np .bool | object_ ], / ) -> complex : ...
2256
2248
2257
2249
def __len__ (self ) -> int : ...
2258
2250
def __setitem__ (self , key , value ): ...
@@ -2310,41 +2302,25 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2310
2302
def __ge__ (self : NDArray [Any ], other : _ArrayLikeObject_co , / ) -> NDArray [np .bool ]: ...
2311
2303
2312
2304
# Unary ops
2313
- @overload
2314
- def __abs__ (self : NDArray [_UnknownType ]) -> NDArray [Any ]: ...
2315
- @overload
2316
- def __abs__ (self : NDArray [np .bool ]) -> NDArray [np .bool ]: ...
2317
- @overload
2318
- def __abs__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]]) -> NDArray [floating [_NBit1 ]]: ...
2319
- @overload
2320
- def __abs__ (self : NDArray [_NumberType ]) -> NDArray [_NumberType ]: ...
2321
- @overload
2322
- def __abs__ (self : NDArray [timedelta64 ]) -> NDArray [timedelta64 ]: ...
2323
- @overload
2324
- def __abs__ (self : NDArray [object_ ]) -> Any : ...
2325
2305
2326
- @overload
2327
- def __invert__ (self : NDArray [_UnknownType ]) -> NDArray [Any ]: ...
2328
- @overload
2329
- def __invert__ (self : NDArray [np .bool ]) -> NDArray [np .bool ]: ...
2330
- @overload
2331
- def __invert__ (self : NDArray [_IntType ]) -> NDArray [_IntType ]: ...
2332
- @overload
2333
- def __invert__ (self : NDArray [object_ ]) -> Any : ...
2334
-
2335
- @overload
2336
- def __pos__ (self : NDArray [_NumberType ]) -> NDArray [_NumberType ]: ...
2337
- @overload
2338
- def __pos__ (self : NDArray [timedelta64 ]) -> NDArray [timedelta64 ]: ...
2339
- @overload
2340
- def __pos__ (self : NDArray [object_ ]) -> Any : ...
2341
-
2342
- @overload
2343
- def __neg__ (self : NDArray [_NumberType ]) -> NDArray [_NumberType ]: ...
2344
- @overload
2345
- def __neg__ (self : NDArray [timedelta64 ]) -> NDArray [timedelta64 ]: ...
2346
- @overload
2347
- def __neg__ (self : NDArray [object_ ]) -> Any : ...
2306
+ # TODO: Uncomment once https://github.com/python/mypy/issues/14070 is fixed
2307
+ # @overload
2308
+ # def __abs__(self: ndarray[_ShapeType, dtypes.Complex64DType], /) -> ndarray[_ShapeType, dtypes.Float32DType]: ...
2309
+ # @overload
2310
+ # def __abs__(self: ndarray[_ShapeType, dtypes.Complex128DType], /) -> ndarray[_ShapeType, dtypes.Float64DType]: ...
2311
+ # @overload
2312
+ # def __abs__(self: ndarray[_ShapeType, dtypes.CLongDoubleDType], /) -> ndarray[_ShapeType, dtypes.LongDoubleDType]: ...
2313
+ # @overload
2314
+ # def __abs__(self: ndarray[_ShapeType, dtype[complex128]], /) -> ndarray[_ShapeType, dtype[float64]]: ...
2315
+ @overload
2316
+ def __abs__ (
2317
+ self : ndarray [_ShapeType , dtype [complexfloating [_NBit_fc ]]], /
2318
+ ) -> ndarray [_ShapeType , dtype [floating [_NBit_fc ]]]: ...
2319
+ @overload
2320
+ def __abs__ (self : _RealArrayT , / ) -> _RealArrayT : ...
2321
+ def __invert__ (self : _IntegralArrayT , / ) -> _IntegralArrayT : ... # noqa: PYI019
2322
+ def __neg__ (self : _NumericArrayT , / ) -> _NumericArrayT : ... # noqa: PYI019
2323
+ def __pos__ (self : _NumericArrayT , / ) -> _NumericArrayT : ... # noqa: PYI019
2348
2324
2349
2325
# Binary ops
2350
2326
@overload
@@ -3094,6 +3070,7 @@ _ScalarType = TypeVar("_ScalarType", bound=generic)
3094
3070
_NBit = TypeVar ("_NBit" , bound = NBitBase )
3095
3071
_NBit1 = TypeVar ("_NBit1" , bound = NBitBase )
3096
3072
_NBit2 = TypeVar ("_NBit2" , bound = NBitBase , default = _NBit1 )
3073
+ _NBit_fc = TypeVar ("_NBit_fc" , _NBitHalf , _NBitSingle , _NBitDouble , _NBitLongDouble )
3097
3074
3098
3075
class generic (_ArrayOrScalarCommon ):
3099
3076
@abstractmethod
0 commit comments