Skip to content

Commit 672009e

Browse files
committed
feat(comment): #1312 (comment)
1 parent e3447cf commit 672009e

File tree

6 files changed

+314
-60
lines changed

6 files changed

+314
-60
lines changed

pandas-stubs/core/series.pyi

Lines changed: 123 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ from pandas.core.dtypes.dtypes import CategoricalDtype
188188

189189
from pandas.plotting import PlotAccessor
190190

191+
_T_NUM_NON_BOOL = TypeVar("_T_NUM_NON_BOOL", int, float, complex)
191192
_T_INT = TypeVar("_T_INT", bound=int)
192193
_T_COMPLEX = TypeVar("_T_COMPLEX", bound=complex)
193194

@@ -2087,39 +2088,60 @@ class Series(IndexOpsMixin[S1], NDFrame):
20872088
@overload
20882089
def __sub__(self, other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
20892090
@overload
2091+
def __sub__(
2092+
self: Series[bool],
2093+
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
2094+
) -> Series[_T_NUM_NON_BOOL]: ...
2095+
@overload
2096+
def __sub__(self: Series[bool], other: np_ndarray_anyint) -> Series[int]: ...
2097+
@overload
2098+
def __sub__(self: Series[bool], other: np_ndarray_float) -> Series[float]: ...
2099+
@overload
2100+
def __sub__(
2101+
self: Series[int],
2102+
other: (
2103+
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
2104+
),
2105+
) -> Series[int]: ...
2106+
@overload
20902107
def __sub__(
20912108
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
20922109
) -> Series[_T_COMPLEX]: ...
20932110
@overload
2094-
def __sub__(self: Series[int], other: np_ndarray_anyint) -> Series[int]: ...
2095-
@overload
20962111
def __sub__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
20972112
@overload
2098-
def __sub__(self: Series[int], other: np_ndarray_complex) -> Series[complex]: ...
2099-
@overload
21002113
def __sub__(
21012114
self: Series[float],
2102-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2115+
other: (
2116+
_T_INT
2117+
| Sequence[_T_INT]
2118+
| np_ndarray_bool
2119+
| np_ndarray_anyint
2120+
| np_ndarray_float
2121+
| Series[_T_INT]
2122+
),
21032123
) -> Series[float]: ...
21042124
@overload
21052125
def __sub__(
21062126
self: Series[float],
21072127
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
21082128
) -> Series[_T_COMPLEX]: ...
21092129
@overload
2110-
def __sub__(self: Series[float], other: np_ndarray_complex) -> Series[complex]: ...
2111-
@overload
21122130
def __sub__(
21132131
self: Series[complex],
21142132
other: (
21152133
Sequence[_T_COMPLEX]
2116-
| Series[_T_COMPLEX]
2134+
| np_ndarray_bool
21172135
| np_ndarray_anyint
21182136
| np_ndarray_float
2119-
| np_ndarray_complex
2137+
| Series[_T_COMPLEX]
21202138
),
21212139
) -> Series[complex]: ...
21222140
@overload
2141+
def __sub__(
2142+
self: Series[_T_COMPLEX], other: np_ndarray_complex
2143+
) -> Series[complex]: ...
2144+
@overload
21232145
def __sub__(
21242146
self: Series[Timestamp],
21252147
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
@@ -2134,22 +2156,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
21342156
@overload
21352157
def sub(
21362158
self: Series[Never],
2137-
other: Scalar | _ListLike | Series,
2159+
other: complex | _ListLike | Series,
21382160
level: Level | None = None,
21392161
fill_value: float | None = None,
21402162
axis: int = 0,
21412163
) -> Series: ...
21422164
@overload
21432165
def sub(
2144-
self: Series[int],
2145-
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2166+
self: Series[bool],
2167+
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
21462168
level: Level | None = None,
21472169
fill_value: float | None = None,
21482170
axis: int = 0,
2149-
) -> Series[_T_COMPLEX]: ...
2171+
) -> Series[_T_NUM_NON_BOOL]: ...
21502172
@overload
21512173
def sub(
2152-
self: Series[int],
2174+
self: Series[bool],
21532175
other: np_ndarray_anyint,
21542176
level: Level | None = None,
21552177
fill_value: float | None = None,
@@ -2158,58 +2180,75 @@ class Series(IndexOpsMixin[S1], NDFrame):
21582180
@overload
21592181
def sub(
21602182
self: Series[int],
2161-
other: np_ndarray_float,
2183+
other: (
2184+
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
2185+
),
21622186
level: Level | None = None,
21632187
fill_value: float | None = None,
21642188
axis: int = 0,
2165-
) -> Series[float]: ...
2189+
) -> Series[int]: ...
21662190
@overload
21672191
def sub(
21682192
self: Series[int],
2169-
other: np_ndarray_complex,
2193+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
21702194
level: Level | None = None,
21712195
fill_value: float | None = None,
21722196
axis: int = 0,
2173-
) -> Series[complex]: ...
2197+
) -> Series[_T_COMPLEX]: ...
21742198
@overload
21752199
def sub(
2176-
self: Series[float],
2177-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2200+
self: Series[_T_INT],
2201+
other: np_ndarray_float,
21782202
level: Level | None = None,
21792203
fill_value: float | None = None,
21802204
axis: int = 0,
21812205
) -> Series[float]: ...
21822206
@overload
21832207
def sub(
21842208
self: Series[float],
2185-
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2209+
other: (
2210+
_T_INT
2211+
| Sequence[_T_INT]
2212+
| np_ndarray_bool
2213+
| np_ndarray_anyint
2214+
| np_ndarray_float
2215+
| Series[_T_INT]
2216+
),
21862217
level: Level | None = None,
21872218
fill_value: float | None = None,
21882219
axis: int = 0,
2189-
) -> Series[_T_COMPLEX]: ...
2220+
) -> Series[float]: ...
21902221
@overload
21912222
def sub(
21922223
self: Series[float],
2193-
other: np_ndarray_complex,
2224+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
21942225
level: Level | None = None,
21952226
fill_value: float | None = None,
21962227
axis: int = 0,
2197-
) -> Series[complex]: ...
2228+
) -> Series[_T_COMPLEX]: ...
21982229
@overload
21992230
def sub(
22002231
self: Series[complex],
22012232
other: (
22022233
Sequence[_T_COMPLEX]
2234+
| np_ndarray_bool
22032235
| np_ndarray_anyint
22042236
| np_ndarray_float
2205-
| np_ndarray_complex
22062237
| Series[_T_COMPLEX]
22072238
),
22082239
level: Level | None = None,
22092240
fill_value: float | None = None,
22102241
axis: int = 0,
22112242
) -> Series[complex]: ...
22122243
@overload
2244+
def sub(
2245+
self: Series[_T_COMPLEX],
2246+
other: np_ndarray_complex,
2247+
level: Level | None = None,
2248+
fill_value: float | None = None,
2249+
axis: int = 0,
2250+
) -> Series[complex]: ...
2251+
@overload
22132252
def sub(
22142253
self,
22152254
other: S1 | Series[S1],
@@ -2218,39 +2257,54 @@ class Series(IndexOpsMixin[S1], NDFrame):
22182257
axis: int = 0,
22192258
) -> Self: ...
22202259
@overload
2221-
def __rsub__(self: Series[Never], other: Scalar | _ListLike) -> Series: ...
2260+
def __rsub__(self: Series[Never], other: complex | _ListLike) -> Series: ...
22222261
@overload
22232262
def __rsub__(
2224-
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2225-
) -> Series[_T_COMPLEX]: ...
2263+
self: Series[bool], other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL]
2264+
) -> Series[_T_NUM_NON_BOOL]: ...
22262265
@overload
2227-
def __rsub__(self: Series[int], other: np_ndarray_anyint) -> Series[int]: ...
2266+
def __rsub__(self: Series[bool], other: np_ndarray_anyint) -> Series[int]: ...
22282267
@overload
2229-
def __rsub__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
2268+
def __rsub__(
2269+
self: Series[int],
2270+
other: bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint,
2271+
) -> Series[int]: ...
22302272
@overload
2231-
def __rsub__(self: Series[int], other: np_ndarray_complex) -> Series[complex]: ...
2273+
def __rsub__(
2274+
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2275+
) -> Series[_T_COMPLEX]: ...
2276+
@overload
2277+
def __rsub__(self: Series[_T_INT], other: np_ndarray_float) -> Series[float]: ...
22322278
@overload
22332279
def __rsub__(
22342280
self: Series[float],
2235-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float,
2281+
other: (
2282+
_T_INT
2283+
| Sequence[_T_INT]
2284+
| np_ndarray_bool
2285+
| np_ndarray_anyint
2286+
| np_ndarray_float
2287+
),
22362288
) -> Series[float]: ...
22372289
@overload
22382290
def __rsub__(
22392291
self: Series[float], other: _T_COMPLEX | Sequence[_T_COMPLEX]
22402292
) -> Series[_T_COMPLEX]: ...
22412293
@overload
2242-
def __rsub__(self: Series[float], other: np_ndarray_complex) -> Series[complex]: ...
2243-
@overload
22442294
def __rsub__(
22452295
self: Series[complex],
22462296
other: (
2247-
np_ndarray_anyint
2297+
Sequence[_T_COMPLEX]
2298+
| np_ndarray_bool
2299+
| np_ndarray_anyint
22482300
| np_ndarray_float
2249-
| np_ndarray_complex
2250-
| Sequence[_T_COMPLEX]
22512301
),
22522302
) -> Series[complex]: ...
22532303
@overload
2304+
def __rsub__(
2305+
self: Series[_T_COMPLEX], other: np_ndarray_complex
2306+
) -> Series[complex]: ...
2307+
@overload
22542308
def __rsub__(self, other: S1) -> Self: ...
22552309
@overload
22562310
def rsub(
@@ -2262,15 +2316,15 @@ class Series(IndexOpsMixin[S1], NDFrame):
22622316
) -> Series: ...
22632317
@overload
22642318
def rsub(
2265-
self: Series[int],
2266-
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2319+
self: Series[bool],
2320+
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
22672321
level: Level | None = None,
22682322
fill_value: float | None = None,
22692323
axis: int = 0,
2270-
) -> Series[_T_COMPLEX]: ...
2324+
) -> Series[_T_NUM_NON_BOOL]: ...
22712325
@overload
22722326
def rsub(
2273-
self: Series[int],
2327+
self: Series[bool],
22742328
other: np_ndarray_anyint,
22752329
level: Level | None = None,
22762330
fill_value: float | None = None,
@@ -2279,58 +2333,75 @@ class Series(IndexOpsMixin[S1], NDFrame):
22792333
@overload
22802334
def rsub(
22812335
self: Series[int],
2282-
other: np_ndarray_float,
2336+
other: (
2337+
bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint | Series[bool]
2338+
),
22832339
level: Level | None = None,
22842340
fill_value: float | None = None,
22852341
axis: int = 0,
2286-
) -> Series[float]: ...
2342+
) -> Series[int]: ...
22872343
@overload
22882344
def rsub(
22892345
self: Series[int],
2290-
other: np_ndarray_complex,
2346+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
22912347
level: Level | None = None,
22922348
fill_value: float | None = None,
22932349
axis: int = 0,
2294-
) -> Series[complex]: ...
2350+
) -> Series[_T_COMPLEX]: ...
22952351
@overload
22962352
def rsub(
2297-
self: Series[float],
2298-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2353+
self: Series[_T_INT],
2354+
other: np_ndarray_float,
22992355
level: Level | None = None,
23002356
fill_value: float | None = None,
23012357
axis: int = 0,
23022358
) -> Series[float]: ...
23032359
@overload
23042360
def rsub(
23052361
self: Series[float],
2306-
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2362+
other: (
2363+
_T_INT
2364+
| Sequence[_T_INT]
2365+
| np_ndarray_bool
2366+
| np_ndarray_anyint
2367+
| np_ndarray_float
2368+
| Series[_T_INT]
2369+
),
23072370
level: Level | None = None,
23082371
fill_value: float | None = None,
23092372
axis: int = 0,
2310-
) -> Series[_T_COMPLEX]: ...
2373+
) -> Series[float]: ...
23112374
@overload
23122375
def rsub(
23132376
self: Series[float],
2314-
other: np_ndarray_complex,
2377+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
23152378
level: Level | None = None,
23162379
fill_value: float | None = None,
23172380
axis: int = 0,
2318-
) -> Series[complex]: ...
2381+
) -> Series[_T_COMPLEX]: ...
23192382
@overload
23202383
def rsub(
23212384
self: Series[complex],
23222385
other: (
23232386
Sequence[_T_COMPLEX]
2387+
| np_ndarray_bool
23242388
| np_ndarray_anyint
23252389
| np_ndarray_float
2326-
| np_ndarray_complex
23272390
| Series[_T_COMPLEX]
23282391
),
23292392
level: Level | None = None,
23302393
fill_value: float | None = None,
23312394
axis: int = 0,
23322395
) -> Series[complex]: ...
23332396
@overload
2397+
def rsub(
2398+
self: Series[_T_COMPLEX],
2399+
other: np_ndarray_complex,
2400+
level: Level | None = None,
2401+
fill_value: float | None = None,
2402+
axis: int = 0,
2403+
) -> Series[complex]: ...
2404+
@overload
23342405
def rsub(
23352406
self,
23362407
other: S1 | Series[S1],

0 commit comments

Comments
 (0)