@@ -25,6 +25,7 @@ from typing import (
25
25
Generic ,
26
26
Literal ,
27
27
NoReturn ,
28
+ TypeVar ,
28
29
final ,
29
30
overload ,
30
31
)
@@ -77,7 +78,7 @@ from pandas.core.indexing import (
77
78
_IndexSliceTuple ,
78
79
_LocIndexer ,
79
80
)
80
- from pandas .core .strings import StringMethods
81
+ from pandas .core .strings . accessor import StringMethods
81
82
from pandas .core .window import (
82
83
Expanding ,
83
84
ExponentialMovingWindow ,
@@ -175,6 +176,8 @@ from pandas._typing import (
175
176
VoidDtypeArg ,
176
177
WriteBuffer ,
177
178
np_ndarray_anyint ,
179
+ np_ndarray_complex ,
180
+ np_ndarray_float ,
178
181
npt ,
179
182
num ,
180
183
)
@@ -184,6 +187,8 @@ from pandas.core.dtypes.dtypes import CategoricalDtype
184
187
185
188
from pandas .plotting import PlotAccessor
186
189
190
+ _T_COMPLEX = TypeVar ("_T_COMPLEX" , bound = complex )
191
+
187
192
class _iLocIndexerSeries (_iLocIndexer , Generic [S1 ]):
188
193
# get item
189
194
@overload
@@ -1617,12 +1622,48 @@ class Series(IndexOpsMixin[S1], NDFrame):
1617
1622
# just failed to generate these so I couldn't match
1618
1623
# them up.
1619
1624
@overload
1620
- def __add__ (self , other : S1 | Self ) -> Self : ...
1621
- @overload
1622
1625
def __add__ (
1623
- self ,
1624
- other : num | _str | timedelta | Timedelta | _ListLike | Series | np . timedelta64 ,
1626
+ self : Series [ Never ] ,
1627
+ other : Scalar | _ListLike | Series ,
1625
1628
) -> Series : ...
1629
+ @overload
1630
+ def __add__ (self , other : Series [Never ]) -> Series : ...
1631
+ @overload
1632
+ def __add__ (
1633
+ self : Series [int ], other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ]
1634
+ ) -> Series [_T_COMPLEX ]: ...
1635
+ @overload
1636
+ def __add__ (self : Series [int ], other : np_ndarray_anyint ) -> Series [int ]: ...
1637
+ @overload
1638
+ def __add__ (self : Series [int ], other : np_ndarray_float ) -> Series [float ]: ...
1639
+ @overload
1640
+ def __add__ (self : Series [int ], other : np_ndarray_complex ) -> Series [complex ]: ...
1641
+ @overload
1642
+ def __add__ (
1643
+ self : Series [float ],
1644
+ other : int | Sequence [int ] | np_ndarray_anyint | np_ndarray_float | Series [int ],
1645
+ ) -> Series [float ]: ...
1646
+ @overload
1647
+ def __add__ (
1648
+ self : Series [float ],
1649
+ other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ],
1650
+ ) -> Series [_T_COMPLEX ]: ...
1651
+ @overload
1652
+ def __add__ (self : Series [float ], other : np_ndarray_complex ) -> Series [complex ]: ...
1653
+ @overload
1654
+ def __add__ (
1655
+ self : Series [complex ],
1656
+ other : (
1657
+ _T_COMPLEX
1658
+ | Sequence [_T_COMPLEX ]
1659
+ | Series [_T_COMPLEX ]
1660
+ | np_ndarray_anyint
1661
+ | np_ndarray_float
1662
+ | np_ndarray_complex
1663
+ ),
1664
+ ) -> Series [complex ]: ...
1665
+ @overload
1666
+ def __add__ (self , other : S1 | Self ) -> Self : ...
1626
1667
# ignore needed for mypy as we want different results based on the arguments
1627
1668
@overload # type: ignore[override]
1628
1669
def __and__ ( # pyright: ignore[reportOverlappingOverload]
@@ -1661,9 +1702,40 @@ class Series(IndexOpsMixin[S1], NDFrame):
1661
1702
@overload
1662
1703
def __or__ (self , other : int | np_ndarray_anyint | Series [int ]) -> Series [int ]: ...
1663
1704
@overload
1664
- def __radd__ (self , other : S1 | Series [S1 ]) -> Self : ...
1705
+ def __radd__ (self : Series [Never ], other : Scalar | _ListLike ) -> Series : ...
1706
+ @overload
1707
+ def __radd__ (
1708
+ self : Series [int ], other : _T_COMPLEX | Sequence [_T_COMPLEX ]
1709
+ ) -> Series [_T_COMPLEX ]: ...
1710
+ @overload
1711
+ def __radd__ (self : Series [int ], other : np_ndarray_anyint ) -> Series [int ]: ...
1712
+ @overload
1713
+ def __radd__ (self : Series [int ], other : np_ndarray_float ) -> Series [float ]: ...
1714
+ @overload
1715
+ def __radd__ (self : Series [int ], other : np_ndarray_complex ) -> Series [complex ]: ...
1716
+ @overload
1717
+ def __radd__ (
1718
+ self : Series [float ],
1719
+ other : int | Sequence [int ] | np_ndarray_anyint | np_ndarray_float ,
1720
+ ) -> Series [float ]: ...
1721
+ @overload
1722
+ def __radd__ (
1723
+ self : Series [float ], other : _T_COMPLEX | Sequence [_T_COMPLEX ]
1724
+ ) -> Series [_T_COMPLEX ]: ...
1665
1725
@overload
1666
- def __radd__ (self , other : num | _str | _ListLike | Series ) -> Series : ...
1726
+ def __radd__ (self : Series [float ], other : np_ndarray_complex ) -> Series [complex ]: ...
1727
+ @overload
1728
+ def __radd__ (
1729
+ self : Series [complex ],
1730
+ other : (
1731
+ np_ndarray_anyint
1732
+ | np_ndarray_float
1733
+ | np_ndarray_complex
1734
+ | Sequence [_T_COMPLEX ]
1735
+ ),
1736
+ ) -> Series [complex ]: ...
1737
+ @overload
1738
+ def __radd__ (self , other : S1 ) -> Self : ...
1667
1739
# ignore needed for mypy as we want different results based on the arguments
1668
1740
@overload # type: ignore[override]
1669
1741
def __rand__ ( # pyright: ignore[reportOverlappingOverload]
@@ -1738,13 +1810,92 @@ class Series(IndexOpsMixin[S1], NDFrame):
1738
1810
@property
1739
1811
def loc (self ) -> _LocIndexerSeries [S1 ]: ...
1740
1812
# Methods
1813
+ @overload
1814
+ def add (
1815
+ self : Series [Never ],
1816
+ other : Scalar | _ListLike | Series ,
1817
+ level : Level | None = ...,
1818
+ fill_value : float | None = ...,
1819
+ axis : int = ...,
1820
+ ) -> Series : ...
1821
+ @overload
1822
+ def add (
1823
+ self : Series [int ],
1824
+ other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ],
1825
+ level : Level | None = ...,
1826
+ fill_value : float | None = ...,
1827
+ axis : int = ...,
1828
+ ) -> Series [_T_COMPLEX ]: ...
1829
+ @overload
1830
+ def add (
1831
+ self : Series [int ],
1832
+ other : np_ndarray_anyint ,
1833
+ level : Level | None = ...,
1834
+ fill_value : float | None = ...,
1835
+ axis : int = ...,
1836
+ ) -> Series [int ]: ...
1837
+ @overload
1838
+ def add (
1839
+ self : Series [int ],
1840
+ other : np_ndarray_float ,
1841
+ level : Level | None = ...,
1842
+ fill_value : float | None = ...,
1843
+ axis : int = ...,
1844
+ ) -> Series [float ]: ...
1845
+ @overload
1846
+ def add (
1847
+ self : Series [int ],
1848
+ other : np_ndarray_complex ,
1849
+ level : Level | None = ...,
1850
+ fill_value : float | None = ...,
1851
+ axis : int = ...,
1852
+ ) -> Series [complex ]: ...
1853
+ @overload
1854
+ def add (
1855
+ self : Series [float ],
1856
+ other : int | Sequence [int ] | np_ndarray_anyint | np_ndarray_float | Series [int ],
1857
+ level : Level | None = ...,
1858
+ fill_value : float | None = ...,
1859
+ axis : int = ...,
1860
+ ) -> Series [float ]: ...
1861
+ @overload
1862
+ def add (
1863
+ self : Series [float ],
1864
+ other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ],
1865
+ level : Level | None = ...,
1866
+ fill_value : float | None = ...,
1867
+ axis : int = ...,
1868
+ ) -> Series [_T_COMPLEX ]: ...
1869
+ @overload
1870
+ def add (
1871
+ self : Series [float ],
1872
+ other : np_ndarray_complex ,
1873
+ level : Level | None = ...,
1874
+ fill_value : float | None = ...,
1875
+ axis : int = ...,
1876
+ ) -> Series [complex ]: ...
1877
+ @overload
1878
+ def add (
1879
+ self : Series [complex ],
1880
+ other : (
1881
+ Sequence [_T_COMPLEX ]
1882
+ | np_ndarray_anyint
1883
+ | np_ndarray_float
1884
+ | np_ndarray_complex
1885
+ | Series [_T_COMPLEX ]
1886
+ ),
1887
+ level : Level | None = ...,
1888
+ fill_value : float | None = ...,
1889
+ axis : int = ...,
1890
+ ) -> Series [complex ]: ...
1891
+ @overload
1741
1892
def add (
1742
1893
self ,
1743
- other : Series [ S1 ] | Scalar ,
1894
+ other : S1 | Series [ S1 ] ,
1744
1895
level : Level | None = ...,
1745
1896
fill_value : float | None = ...,
1746
1897
axis : int = ...,
1747
- ) -> Series [ S1 ] : ...
1898
+ ) -> Self : ...
1748
1899
def all (
1749
1900
self ,
1750
1901
axis : AxisIndex = ...,
@@ -1984,13 +2135,92 @@ class Series(IndexOpsMixin[S1], NDFrame):
1984
2135
min_count : int = ...,
1985
2136
** kwargs : Any ,
1986
2137
) -> Scalar : ...
2138
+ @overload
2139
+ def radd (
2140
+ self : Series [Never ],
2141
+ other : Scalar | _ListLike | Series ,
2142
+ level : Level | None = ...,
2143
+ fill_value : float | None = ...,
2144
+ axis : AxisIndex = ...,
2145
+ ) -> Series : ...
2146
+ @overload
2147
+ def radd (
2148
+ self : Series [int ],
2149
+ other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ],
2150
+ level : Level | None = ...,
2151
+ fill_value : float | None = ...,
2152
+ axis : int = ...,
2153
+ ) -> Series [_T_COMPLEX ]: ...
2154
+ @overload
2155
+ def radd (
2156
+ self : Series [int ],
2157
+ other : np_ndarray_anyint ,
2158
+ level : Level | None = ...,
2159
+ fill_value : float | None = ...,
2160
+ axis : int = ...,
2161
+ ) -> Series [int ]: ...
2162
+ @overload
2163
+ def radd (
2164
+ self : Series [int ],
2165
+ other : np_ndarray_float ,
2166
+ level : Level | None = ...,
2167
+ fill_value : float | None = ...,
2168
+ axis : int = ...,
2169
+ ) -> Series [float ]: ...
2170
+ @overload
2171
+ def radd (
2172
+ self : Series [int ],
2173
+ other : np_ndarray_complex ,
2174
+ level : Level | None = ...,
2175
+ fill_value : float | None = ...,
2176
+ axis : int = ...,
2177
+ ) -> Series [complex ]: ...
2178
+ @overload
2179
+ def radd (
2180
+ self : Series [float ],
2181
+ other : int | Sequence [int ] | np_ndarray_anyint | np_ndarray_float | Series [int ],
2182
+ level : Level | None = ...,
2183
+ fill_value : float | None = ...,
2184
+ axis : int = ...,
2185
+ ) -> Series [float ]: ...
2186
+ @overload
2187
+ def radd (
2188
+ self : Series [float ],
2189
+ other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ],
2190
+ level : Level | None = ...,
2191
+ fill_value : float | None = ...,
2192
+ axis : int = ...,
2193
+ ) -> Series [_T_COMPLEX ]: ...
2194
+ @overload
2195
+ def radd (
2196
+ self : Series [float ],
2197
+ other : np_ndarray_complex ,
2198
+ level : Level | None = ...,
2199
+ fill_value : float | None = ...,
2200
+ axis : int = ...,
2201
+ ) -> Series [complex ]: ...
2202
+ @overload
2203
+ def radd (
2204
+ self : Series [complex ],
2205
+ other : (
2206
+ Sequence [_T_COMPLEX ]
2207
+ | np_ndarray_anyint
2208
+ | np_ndarray_float
2209
+ | np_ndarray_complex
2210
+ | Series [_T_COMPLEX ]
2211
+ ),
2212
+ level : Level | None = ...,
2213
+ fill_value : float | None = ...,
2214
+ axis : int = ...,
2215
+ ) -> Series [complex ]: ...
2216
+ @overload
1987
2217
def radd (
1988
2218
self ,
1989
- other : Series [ S1 ] | Scalar ,
2219
+ other : S1 | Series [ S1 ] ,
1990
2220
level : Level | None = ...,
1991
2221
fill_value : float | None = ...,
1992
2222
axis : AxisIndex = ...,
1993
- ) -> Series [ S1 ] : ...
2223
+ ) -> Self : ...
1994
2224
def rdivmod (
1995
2225
self ,
1996
2226
other : Series [S1 ] | Scalar ,
@@ -2394,7 +2624,7 @@ class PeriodSeries(Series[Period]):
2394
2624
) -> Never : ...
2395
2625
2396
2626
class OffsetSeries (Series [BaseOffset ]):
2397
- @overload # type: ignore[override]
2627
+ @overload
2398
2628
def __radd__ (self , other : Period ) -> PeriodSeries : ...
2399
2629
@overload
2400
2630
def __radd__ ( # pyright: ignore[reportIncompatibleMethodOverride]
0 commit comments