diff options
author | Bas van Beek <b.f.van.beek@vu.nl> | 2021-06-19 10:57:18 +0200 |
---|---|---|
committer | Bas van Beek <43369155+BvB93@users.noreply.github.com> | 2021-06-20 15:56:42 +0200 |
commit | c66ffd98ea1ca734862504bd68c382360152b61c (patch) | |
tree | 6bc908c2ca7f6f2c480986865b1e1501885e245b | |
parent | d3809f228f83f3dce74f48705591d09d7d7f1491 (diff) | |
download | numpy-c66ffd98ea1ca734862504bd68c382360152b61c.tar.gz |
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
-rw-r--r-- | numpy/__init__.pyi | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 7efe73010..531a46ee6 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -1633,6 +1633,14 @@ _ArrayTD64_co = NDArray[Union[bool_, integer[Any], timedelta64]] class _SupportsItem(Protocol[_T_co]): def item(self, __args: Any) -> _T_co: ... +class _SupportsReal(Protocol[_T_co]): + @property + def real(self) -> _T_co: ... + +class _SupportsImag(Protocol[_T_co]): + @property + def imag(self) -> _T_co: ... + class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]): @property def base(self) -> Optional[ndarray]: ... @@ -1641,11 +1649,15 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]): @property def size(self) -> int: ... @property - def real(self: _ArraySelf) -> _ArraySelf: ... + def real( + self: NDArray[_SupportsReal[_ScalarType]], # type: ignore[type-var] + ) -> ndarray[_ShapeType, dtype[_ScalarType]]: ... @real.setter def real(self, value: ArrayLike) -> None: ... @property - def imag(self: _ArraySelf) -> _ArraySelf: ... + def imag( + self: NDArray[_SupportsImag[_ScalarType]], # type: ignore[type-var] + ) -> ndarray[_ShapeType, dtype[_ScalarType]]: ... @imag.setter def imag(self, value: ArrayLike) -> None: ... def __new__( |