Skip to content

Commit 1a1ff50

Browse files
committed
feat(comment): #1350 (comment)
1 parent 94d68ff commit 1a1ff50

File tree

13 files changed

+260
-32
lines changed

13 files changed

+260
-32
lines changed

pandas-stubs/core/series.pyi

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,13 +1631,15 @@ class Series(IndexOpsMixin[S1], NDFrame):
16311631
@overload
16321632
def __add__(self: Series[Never], other: _str) -> Never: ...
16331633
@overload
1634-
def __add__(self: Series[Never], other: complex | _ListLike | Series) -> Series: ...
1634+
def __add__(
1635+
self: Series[Never], other: complex | _ListLike | Index | Series
1636+
) -> Series: ...
16351637
@overload
1636-
def __add__(self, other: Series[Never]) -> Series: ...
1638+
def __add__(self, other: Index[Never] | Series[Never]) -> Series: ...
16371639
@overload
16381640
def __add__(
16391641
self: Series[bool],
1640-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1642+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
16411643
) -> Series[T_COMPLEX]: ...
16421644
@overload
16431645
def __add__(self: Series[bool], other: np_ndarray_bool) -> Series[bool]: ...
@@ -1651,13 +1653,18 @@ class Series(IndexOpsMixin[S1], NDFrame):
16511653
def __add__(
16521654
self: Series[int],
16531655
other: (
1654-
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
1656+
bool
1657+
| Sequence[bool]
1658+
| np_ndarray_bool
1659+
| np_ndarray_anyint
1660+
| Index[bool]
1661+
| Series[bool]
16551662
),
16561663
) -> Series[int]: ...
16571664
@overload
16581665
def __add__(
16591666
self: Series[int],
1660-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1667+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
16611668
) -> Series[T_COMPLEX]: ...
16621669
@overload
16631670
def __add__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
@@ -1672,13 +1679,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
16721679
| np_ndarray_bool
16731680
| np_ndarray_anyint
16741681
| np_ndarray_float
1682+
| Index[T_INT]
16751683
| Series[T_INT]
16761684
),
16771685
) -> Series[float]: ...
16781686
@overload
16791687
def __add__(
16801688
self: Series[float],
1681-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1689+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
16821690
) -> Series[T_COMPLEX]: ...
16831691
@overload
16841692
def __add__(self: Series[float], other: np_ndarray_complex) -> Series[complex]: ...
@@ -1692,6 +1700,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
16921700
| np_ndarray_anyint
16931701
| np_ndarray_float
16941702
| np_ndarray_complex
1703+
| Index[T_COMPLEX]
16951704
| Series[T_COMPLEX]
16961705
),
16971706
) -> Series[complex]: ...
@@ -1704,7 +1713,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
17041713
) -> Never: ...
17051714
@overload
17061715
def __add__(
1707-
self: Series[_str], other: _str | Sequence[_str] | np_ndarray_str | Series[_str]
1716+
self: Series[_str],
1717+
other: _str | Sequence[_str] | np_ndarray_str | Index[_str] | Series[_str],
17081718
) -> Series[_str]: ...
17091719
@overload
17101720
def add(
@@ -1717,7 +1727,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
17171727
@overload
17181728
def add(
17191729
self: Series[Never],
1720-
other: complex | _ListLike | Series,
1730+
other: complex | _ListLike | Index | Series,
17211731
level: Level | None = None,
17221732
fill_value: float | None = None,
17231733
axis: int = 0,
@@ -1733,7 +1743,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
17331743
@overload
17341744
def add(
17351745
self: Series[bool],
1736-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1746+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
17371747
level: Level | None = None,
17381748
fill_value: float | None = None,
17391749
axis: int = 0,
@@ -1774,7 +1784,12 @@ class Series(IndexOpsMixin[S1], NDFrame):
17741784
def add(
17751785
self: Series[int],
17761786
other: (
1777-
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
1787+
bool
1788+
| Sequence[bool]
1789+
| np_ndarray_bool
1790+
| np_ndarray_anyint
1791+
| Index[bool]
1792+
| Series[bool]
17781793
),
17791794
level: Level | None = None,
17801795
fill_value: float | None = None,
@@ -1783,7 +1798,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
17831798
@overload
17841799
def add(
17851800
self: Series[int],
1786-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1801+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
17871802
level: Level | None = None,
17881803
fill_value: float | None = None,
17891804
axis: int = 0,
@@ -1813,6 +1828,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
18131828
| np_ndarray_bool
18141829
| np_ndarray_anyint
18151830
| np_ndarray_float
1831+
| Index[T_INT]
18161832
| Series[T_INT]
18171833
),
18181834
level: Level | None = None,
@@ -1822,7 +1838,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
18221838
@overload
18231839
def add(
18241840
self: Series[float],
1825-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1841+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
18261842
level: Level | None = None,
18271843
fill_value: float | None = None,
18281844
axis: int = 0,
@@ -1845,6 +1861,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
18451861
| np_ndarray_anyint
18461862
| np_ndarray_float
18471863
| np_ndarray_complex
1864+
| Index[T_COMPLEX]
18481865
| Series[T_COMPLEX]
18491866
),
18501867
level: Level | None = None,
@@ -1854,7 +1871,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
18541871
@overload
18551872
def add(
18561873
self: Series[_str],
1857-
other: _str | Sequence[_str] | np_ndarray_str | Series[_str],
1874+
other: _str | Sequence[_str] | np_ndarray_str | Index[_str] | Series[_str],
18581875
level: Level | None = None,
18591876
fill_value: float | None = None,
18601877
axis: int = 0,
@@ -1863,12 +1880,12 @@ class Series(IndexOpsMixin[S1], NDFrame):
18631880
def __radd__(self: Series[Never], other: _str) -> Never: ...
18641881
@overload
18651882
def __radd__(
1866-
self: Series[Never], other: complex | _ListLike | Series
1883+
self: Series[Never], other: complex | _ListLike | Index | Series
18671884
) -> Series: ...
18681885
@overload
18691886
def __radd__(
18701887
self: Series[bool],
1871-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1888+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
18721889
) -> Series[T_COMPLEX]: ...
18731890
@overload
18741891
def __radd__(self: Series[bool], other: np_ndarray_bool) -> Series[bool]: ...
@@ -1880,12 +1897,18 @@ class Series(IndexOpsMixin[S1], NDFrame):
18801897
def __radd__(
18811898
self: Series[int],
18821899
other: (
1883-
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
1900+
bool
1901+
| Sequence[bool]
1902+
| np_ndarray_bool
1903+
| np_ndarray_anyint
1904+
| Index[bool]
1905+
| Series[bool]
18841906
),
18851907
) -> Series[int]: ...
18861908
@overload
18871909
def __radd__(
1888-
self: Series[int], other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX]
1910+
self: Series[int],
1911+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
18891912
) -> Series[T_COMPLEX]: ...
18901913
@overload
18911914
def __radd__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
@@ -1898,13 +1921,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
18981921
| np_ndarray_bool
18991922
| np_ndarray_anyint
19001923
| np_ndarray_float
1924+
| Index[T_INT]
19011925
| Series[T_INT]
19021926
),
19031927
) -> Series[float]: ...
19041928
@overload
19051929
def __radd__(
19061930
self: Series[float],
1907-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1931+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
19081932
) -> Series[T_COMPLEX]: ...
19091933
@overload
19101934
def __radd__(
@@ -1915,6 +1939,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19151939
| np_ndarray_bool
19161940
| np_ndarray_anyint
19171941
| np_ndarray_float
1942+
| Index[T_COMPLEX]
19181943
| Series[T_COMPLEX]
19191944
),
19201945
) -> Series[complex]: ...
@@ -1931,7 +1956,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
19311956
) -> Never: ...
19321957
@overload
19331958
def __radd__(
1934-
self: Series[_str], other: _str | Sequence[_str] | np_ndarray_str | Series[_str]
1959+
self: Series[_str],
1960+
other: _str | Sequence[_str] | np_ndarray_str | Index[_str] | Series[_str],
19351961
) -> Series[_str]: ...
19361962
@overload
19371963
def radd(
@@ -1944,7 +1970,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19441970
@overload
19451971
def radd(
19461972
self: Series[Never],
1947-
other: complex | _ListLike | Series,
1973+
other: complex | _ListLike | Index | Series,
19481974
level: Level | None = None,
19491975
fill_value: float | None = None,
19501976
axis: int = 0,
@@ -1960,7 +1986,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19601986
@overload
19611987
def radd(
19621988
self: Series[bool],
1963-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
1989+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
19641990
level: Level | None = None,
19651991
fill_value: float | None = None,
19661992
axis: int = 0,
@@ -1993,7 +2019,12 @@ class Series(IndexOpsMixin[S1], NDFrame):
19932019
def radd(
19942020
self: Series[int],
19952021
other: (
1996-
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
2022+
bool
2023+
| Sequence[bool]
2024+
| np_ndarray_bool
2025+
| np_ndarray_anyint
2026+
| Index[bool]
2027+
| Series[bool]
19972028
),
19982029
level: Level | None = None,
19992030
fill_value: float | None = None,
@@ -2002,7 +2033,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20022033
@overload
20032034
def radd(
20042035
self: Series[int],
2005-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
2036+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
20062037
level: Level | None = None,
20072038
fill_value: float | None = None,
20082039
axis: int = 0,
@@ -2024,6 +2055,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20242055
| np_ndarray_bool
20252056
| np_ndarray_anyint
20262057
| np_ndarray_float
2058+
| Index[T_INT]
20272059
| Series[T_INT]
20282060
),
20292061
level: Level | None = None,
@@ -2033,7 +2065,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20332065
@overload
20342066
def radd(
20352067
self: Series[float],
2036-
other: T_COMPLEX | Sequence[T_COMPLEX] | Series[T_COMPLEX],
2068+
other: T_COMPLEX | Sequence[T_COMPLEX] | Index[T_COMPLEX] | Series[T_COMPLEX],
20372069
level: Level | None = None,
20382070
fill_value: float | None = None,
20392071
axis: int = 0,
@@ -2047,6 +2079,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20472079
| np_ndarray_bool
20482080
| np_ndarray_anyint
20492081
| np_ndarray_float
2082+
| Index[T_COMPLEX]
20502083
| Series[T_COMPLEX]
20512084
),
20522085
level: Level | None = None,
@@ -2064,7 +2097,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20642097
@overload
20652098
def radd(
20662099
self: Series[_str],
2067-
other: _str | Sequence[_str] | np_ndarray_str | Series[_str],
2100+
other: _str | Sequence[_str] | np_ndarray_str | Index[_str] | Series[_str],
20682101
level: Level | None = None,
20692102
fill_value: float | None = None,
20702103
axis: int = 0,

tests/indexes/arithmetic/bool/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_add_numpy_array() -> None:
6565
)
6666

6767

68-
def test_add_pd_series() -> None:
68+
def test_add_pd_index() -> None:
6969
"""Test pd.Index[bool] + pandas index"""
7070
b = pd.Index([True, False, True])
7171
i = pd.Index([2, 3, 5])

tests/indexes/arithmetic/complex/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_add_numpy_array() -> None:
6666
)
6767

6868

69-
def test_add_pd_series() -> None:
69+
def test_add_pd_index() -> None:
7070
"""Test pd.Index[complex] + pandas index"""
7171
b = pd.Index([True, False, True])
7272
i = pd.Index([2, 3, 5])

tests/indexes/arithmetic/float/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_add_numpy_array() -> None:
6464
)
6565

6666

67-
def test_add_pd_series() -> None:
67+
def test_add_pd_index() -> None:
6868
"""Test pd.Index[float] + pandas index"""
6969
b = pd.Index([True, False, True])
7070
i = pd.Index([2, 3, 5])

tests/indexes/arithmetic/int/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_add_numpy_array() -> None:
6464
)
6565

6666

67-
def test_add_pd_series() -> None:
67+
def test_add_pd_index() -> None:
6868
"""Test pd.Index[int] + pandas index"""
6969
b = pd.Index([True, False, True])
7070
i = pd.Index([2, 3, 5])

tests/indexes/arithmetic/str/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_add_numpy_array() -> None:
7474
check(assert_type(r0 + left, Any), pd.Index, str)
7575

7676

77-
def test_add_pd_series() -> None:
77+
def test_add_pd_index() -> None:
7878
"""Test pd.Index[str] + pandas index"""
7979
i = pd.Index([3, 5, 8])
8080
r0 = pd.Index(["a", "bc", "def"])

tests/indexes/arithmetic/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_add_i_numpy_array() -> None:
7676
)
7777

7878

79-
def test_add_i_pd_series() -> None:
79+
def test_add_i_pd_index() -> None:
8080
"""Test pd.Index[Any] (int) + pandas index"""
8181
a = pd.MultiIndex.from_tuples([(1,), (2,), (3,)]).levels[0]
8282
b = pd.Index([True, False, True])

tests/series/arithmetic/bool/test_add.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,33 @@ def test_add_pd_series() -> None:
127127
check(
128128
assert_type(left.radd(c), "pd.Series[complex]"), pd.Series, np.complexfloating
129129
)
130+
131+
132+
def test_add_pd_index() -> None:
133+
"""Test pd.Series[bool] + pandas index"""
134+
b = pd.Index([True, False, True])
135+
i = pd.Index([2, 3, 5])
136+
f = pd.Index([1.0, 2.0, 3.0])
137+
c = pd.Index([1.1j, 2.2j, 4.1j])
138+
139+
check(assert_type(left + b, "pd.Series[bool]"), pd.Series, np.bool_)
140+
check(assert_type(left + i, "pd.Series[int]"), pd.Series, np.integer)
141+
check(assert_type(left + f, "pd.Series[float]"), pd.Series, np.floating)
142+
check(assert_type(left + c, "pd.Series[complex]"), pd.Series, np.complexfloating)
143+
144+
check(assert_type(b + left, "pd.Series[bool]"), pd.Series, np.bool_)
145+
check(assert_type(i + left, "pd.Series[int]"), pd.Series, np.integer)
146+
check(assert_type(f + left, "pd.Series[float]"), pd.Series, np.floating)
147+
check(assert_type(c + left, "pd.Series[complex]"), pd.Series, np.complexfloating)
148+
149+
check(assert_type(left.add(b), "pd.Series[bool]"), pd.Series, np.bool_)
150+
check(assert_type(left.add(i), "pd.Series[int]"), pd.Series, np.integer)
151+
check(assert_type(left.add(f), "pd.Series[float]"), pd.Series, np.floating)
152+
check(assert_type(left.add(c), "pd.Series[complex]"), pd.Series, np.complexfloating)
153+
154+
check(assert_type(left.radd(b), "pd.Series[bool]"), pd.Series, np.bool_)
155+
check(assert_type(left.radd(i), "pd.Series[int]"), pd.Series, np.integer)
156+
check(assert_type(left.radd(f), "pd.Series[float]"), pd.Series, np.floating)
157+
check(
158+
assert_type(left.radd(c), "pd.Series[complex]"), pd.Series, np.complexfloating
159+
)

0 commit comments

Comments
 (0)