diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 06b2d0fc..88f1dfea 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1577,6 +1577,22 @@ class Series(IndexOpsMixin[S1], NDFrame): # just failed to generate these so I couldn't match # them up. @overload + 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__( # pyright: ignore[reportOverlappingOverload] + self: Series[float], other: int + ) -> Series[float]: ... + @overload + 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__( diff --git a/tests/test_series.py b/tests/test_series.py index bd743356..97fb666b 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3538,6 +3538,20 @@ 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) + + 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]) other = pd.Series([1, 2], index=[1, 0])