From 7cabb1926f7aba7b28466dd505e77f7066d08b33 Mon Sep 17 00:00:00 2001 From: shirzady1934 Date: Fri, 14 Mar 2025 01:48:56 +0330 Subject: [PATCH 1/4] issue 1098 added type support for complex in Series __add__ operator --- pandas-stubs/core/series.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 06b2d0fc..3401b29f 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1579,6 +1579,8 @@ class Series(IndexOpsMixin[S1], NDFrame): @overload def __add__(self, other: S1 | Self) -> Self: ... @overload + def __add__(self, other: complex) -> Series[complex]: ... + @overload def __add__( self, other: num | _str | timedelta | Timedelta | _ListLike | Series | np.timedelta64, From 23b588c4848db2aae51a00c6b6d9165715253a10 Mon Sep 17 00:00:00 2001 From: shirzady1934 Date: Fri, 14 Mar 2025 01:49:18 +0330 Subject: [PATCH 2/4] issue 1098 added test for complex in Series __add__ operator --- tests/test_series.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_series.py b/tests/test_series.py index bd743356..0ffa75c0 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3538,6 +3538,12 @@ def test_series_reindex() -> None: check(assert_type(s.reindex([2, 1, 0]), "pd.Series[int]"), pd.Series, np.integer) +def test_series_add_complex() -> None: + c = 1 + 1j + s = pd.Series([1.0, 2.0, 3.0]) + check(assert_type(s + c, "pd.Series[complex]"), pd.Series) + + def test_series_reindex_like() -> None: s = pd.Series([1, 2, 3], index=[0, 1, 2]) other = pd.Series([1, 2], index=[1, 0]) From 1de98d27c61d8abcd16fbbd1669a197e341bd3dc Mon Sep 17 00:00:00 2001 From: kicker_angel Date: Sat, 15 Mar 2025 11:08:00 +0330 Subject: [PATCH 3/4] added right order of __add__ overlay and testcases --- pandas-stubs/core/series.pyi | 14 ++++++++++++-- tests/test_series.py | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 3401b29f..61d2e628 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1577,9 +1577,19 @@ class Series(IndexOpsMixin[S1], NDFrame): # just failed to generate these so I couldn't match # them up. @overload - def __add__(self, other: S1 | Self) -> Self: ... + def __add__(self: Series[int], other: int) -> Series[int]: ... + @overload + def __add__(self: Series[int], other: float) -> Series[float]: ... + @overload + def __add__(self: Series[int], other: complex) -> Series[complex]: ... + @overload + def __add__(self: Series[float], other: int) -> Series[float]: ... @overload - def __add__(self, other: complex) -> Series[complex]: ... + def __add__(self: Series[float], other: float) -> Series[float]: ... + @overload + def __add__(self: Series[float], other: complex) -> Series[complex]: ... + @overload + def __add__(self, other: S1 | Self) -> Self: ... @overload def __add__( self, diff --git a/tests/test_series.py b/tests/test_series.py index 0ffa75c0..97fb666b 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3543,6 +3543,14 @@ def test_series_add_complex() -> None: s = pd.Series([1.0, 2.0, 3.0]) check(assert_type(s + c, "pd.Series[complex]"), pd.Series) + c1 = 1 + s1 = pd.Series([1.0, 2.0, 3.0]) + check(assert_type(s1 + c1, "pd.Series[float]"), pd.Series) + + c2 = 1 + s2 = pd.Series([1, 2, 3]) + check(assert_type(s2 + c2, "pd.Series[int]"), pd.Series) + def test_series_reindex_like() -> None: s = pd.Series([1, 2, 3], index=[0, 1, 2]) From 03d4c42ca322e41d5f96895e49e417c1ad27b45b Mon Sep 17 00:00:00 2001 From: shirzady1934 Date: Mon, 17 Mar 2025 01:13:59 +0330 Subject: [PATCH 4/4] add pyright comment lines --- pandas-stubs/core/series.pyi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 61d2e628..88f1dfea 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1577,13 +1577,17 @@ class Series(IndexOpsMixin[S1], NDFrame): # just failed to generate these so I couldn't match # them up. @overload - def __add__(self: Series[int], other: int) -> Series[int]: ... + def __add__( # pyright: ignore[reportOverlappingOverload] + self: Series[int], other: int + ) -> Series[int]: ... @overload def __add__(self: Series[int], other: float) -> Series[float]: ... @overload def __add__(self: Series[int], other: complex) -> Series[complex]: ... @overload - def __add__(self: Series[float], other: int) -> Series[float]: ... + def __add__( # pyright: ignore[reportOverlappingOverload] + self: Series[float], other: int + ) -> Series[float]: ... @overload def __add__(self: Series[float], other: float) -> Series[float]: ... @overload