8000 MAINT: Fixed an issue with the return-dtype of `ndarray.real` and `imag · numpy/numpy@c66ffd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c66ffd9

Browse files
Bas van BeekBvB93
Bas van Beek
authored andcommitted
MAINT: Fixed an issue with the return-dtype of ndarray.real and `imag
The latter two would previously return complex arrays if the initial array was also complex
1 parent d3809f2 commit c66ffd9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

numpy/__init__.pyi

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,14 @@ _ArrayTD64_co = NDArray[Union[bool_, integer[Any], timedelta64]]
16331633
class _SupportsItem(Protocol[_T_co]):
16341634
def item(self, __args: Any) -> _T_co: ...
16351635

1636+
class _SupportsReal(Protocol[_T_co]):
1637+
@property
1638+
def real(self) -> _T_co: ...
1639+
1640+
class _SupportsImag(Protocol[_T_co]):
1641+
@property
1642+
def imag(self) -> _T_co: ...
1643+
16361644
class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
16371645
@property
16381646
def base(self) -> Optional[ndarray]: ...
@@ -1641,11 +1649,15 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
16411649
@property
16421650
def size(self) -> int: ...
16431651
@property
1644-
def real(self: _ArraySelf) -> _ArraySelf: ...
1652+
def real(
1653+
self: NDArray[_SupportsReal[_ScalarType]], # type: ignore[type-var]
1654+
) -> ndarray[_ShapeType, dtype[_ScalarType]]: ...
16451655
@real.setter
16461656
def real(self, value: ArrayLike) -> None: ...
16471657
@property
1648-
def imag(self: _ArraySelf) -> _ArraySelf: ...
1658+
def imag(
1659+
self: NDArray[_SupportsImag[_ScalarType]], # type: ignore[type-var]
1660+
) -> ndarray[_ShapeType, dtype[_ScalarType]]: ...
16491661
@imag.setter
16501662
def imag(self, value: ArrayLike) -> None: ...
16511663
def __new__(

0 commit comments

Comments
 (0)
0