Skip to content

Commit 1e9b11d

Browse files
committed
fix(comment): completeness #1312 (review)
1 parent 5dab881 commit 1e9b11d

File tree

3 files changed

+148
-57
lines changed

3 files changed

+148
-57
lines changed

pandas-stubs/core/series.pyi

Lines changed: 90 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ 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)
192191
_T_INT = TypeVar("_T_INT", bound=int)
193192
_T_COMPLEX = TypeVar("_T_COMPLEX", bound=complex)
194193

@@ -2072,14 +2071,19 @@ class Series(IndexOpsMixin[S1], NDFrame):
20722071
@overload
20732072
def __sub__(self, other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
20742073
@overload
2074+
def __sub__(self: Series[bool], other: bool | Sequence[bool]) -> Never: ...
2075+
@overload
20752076
def __sub__(
2076-
self: Series[bool],
2077-
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
2078-
) -> Series[_T_NUM_NON_BOOL]: ...
2077+
self: Series[bool], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2078+
) -> Series[_T_COMPLEX]: ...
20792079
@overload
2080-
def __sub__(self: Series[bool], other: np_ndarray_anyint) -> Series[int]: ...
2080+
def __sub__(
2081+
self: Series[bool], other: np_ndarray_anyint | Series[int]
2082+
) -> Series[int]: ...
20812083
@overload
2082-
def __sub__(self: Series[bool], other: np_ndarray_float) -> Series[float]: ...
2084+
def __sub__(
2085+
self: Series[bool], other: np_ndarray_float | Series[float]
2086+
) -> Series[float]: ...
20832087
@overload
20842088
def __sub__(
20852089
self: Series[int],
@@ -2097,8 +2101,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
20972101
def __sub__(
20982102
self: Series[float],
20992103
other: (
2100-
_T_INT
2101-
| Sequence[_T_INT]
2104+
int
2105+
| Sequence[int]
21022106
| np_ndarray_bool
21032107
| np_ndarray_anyint
21042108
| np_ndarray_float
@@ -2114,7 +2118,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
21142118
def __sub__(
21152119
self: Series[complex],
21162120
other: (
2117-
Sequence[_T_COMPLEX]
2121+
_T_COMPLEX
2122+
| Sequence[_T_COMPLEX]
21182123
| np_ndarray_bool
21192124
| np_ndarray_anyint
21202125
| np_ndarray_float
@@ -2123,7 +2128,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
21232128
) -> Series[complex]: ...
21242129
@overload
21252130
def __sub__(
2126-
self: Series[_T_COMPLEX], other: np_ndarray_complex
2131+
self: Series[_T_COMPLEX], other: np_ndarray_complex | Series[complex]
21272132
) -> Series[complex]: ...
21282133
@overload
21292134
def __sub__(
@@ -2136,8 +2141,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
21362141
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
21372142
) -> TimedeltaSeries: ...
21382143
@overload
2139-
def __sub__(self, other: S1 | Series[S1]) -> Self: ...
2140-
@overload
21412144
def sub(
21422145
self: Series[Never],
21432146
other: complex | _ListLike | Series,
@@ -2148,20 +2151,36 @@ class Series(IndexOpsMixin[S1], NDFrame):
21482151
@overload
21492152
def sub(
21502153
self: Series[bool],
2151-
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
2154+
other: bool | Sequence[bool],
21522155
level: Level | None = None,
21532156
fill_value: float | None = None,
21542157
axis: int = 0,
2155-
) -> Series[_T_NUM_NON_BOOL]: ...
2158+
) -> Never: ...
21562159
@overload
21572160
def sub(
21582161
self: Series[bool],
2159-
other: np_ndarray_anyint,
2162+
other: _T_COMPLEX | Sequence[_T_COMPLEX],
2163+
level: Level | None = None,
2164+
fill_value: float | None = None,
2165+
axis: int = 0,
2166+
) -> Series[_T_COMPLEX]: ...
2167+
@overload
2168+
def sub(
2169+
self: Series[bool],
2170+
other: np_ndarray_anyint | Series[int],
21602171
level: Level | None = None,
21612172
fill_value: float | None = None,
21622173
axis: int = 0,
21632174
) -> Series[int]: ...
21642175
@overload
2176+
def sub(
2177+
self: Series[bool],
2178+
other: np_ndarray_float | Series[float],
2179+
level: Level | None = None,
2180+
fill_value: float | None = None,
2181+
axis: int = 0,
2182+
) -> Series[float]: ...
2183+
@overload
21652184
def sub(
21662185
self: Series[int],
21672186
other: (
@@ -2191,8 +2210,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
21912210
def sub(
21922211
self: Series[float],
21932212
other: (
2194-
_T_INT
2195-
| Sequence[_T_INT]
2213+
int
2214+
| Sequence[int]
21962215
| np_ndarray_bool
21972216
| np_ndarray_anyint
21982217
| np_ndarray_float
@@ -2214,7 +2233,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
22142233
def sub(
22152234
self: Series[complex],
22162235
other: (
2217-
Sequence[_T_COMPLEX]
2236+
_T_COMPLEX
2237+
| Sequence[_T_COMPLEX]
22182238
| np_ndarray_bool
22192239
| np_ndarray_anyint
22202240
| np_ndarray_float
@@ -2227,94 +2247,116 @@ class Series(IndexOpsMixin[S1], NDFrame):
22272247
@overload
22282248
def sub(
22292249
self: Series[_T_COMPLEX],
2230-
other: np_ndarray_complex,
2250+
other: np_ndarray_complex | Series[complex],
22312251
level: Level | None = None,
22322252
fill_value: float | None = None,
22332253
axis: int = 0,
22342254
) -> Series[complex]: ...
22352255
@overload
2236-
def sub(
2237-
self,
2238-
other: S1 | Series[S1],
2239-
level: Level | None = None,
2240-
fill_value: float | None = None,
2241-
axis: int = 0,
2242-
) -> Self: ...
2256+
def __rsub__(
2257+
self: Series[Never], other: complex | _ListLike | Series
2258+
) -> Series: ...
22432259
@overload
2244-
def __rsub__(self: Series[Never], other: complex | _ListLike) -> Series: ...
2260+
def __rsub__(self, other: Series[Never]) -> Series: ...
2261+
@overload
2262+
def __rsub__(self: Series[bool], other: bool | Sequence[bool]) -> Never: ...
2263+
@overload
2264+
def __rsub__(
2265+
self: Series[bool], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2266+
) -> Series[_T_COMPLEX]: ...
22452267
@overload
22462268
def __rsub__(
2247-
self: Series[bool], other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL]
2248-
) -> Series[_T_NUM_NON_BOOL]: ...
2269+
self: Series[bool], other: np_ndarray_anyint | Series[int]
2270+
) -> Series[int]: ...
22492271
@overload
2250-
def __rsub__(self: Series[bool], other: np_ndarray_anyint) -> Series[int]: ...
2272+
def __rsub__(
2273+
self: Series[bool], other: np_ndarray_float | Series[float]
2274+
) -> Series[float]: ...
22512275
@overload
22522276
def __rsub__(
22532277
self: Series[int],
22542278
other: bool | Sequence[bool] | np_ndarray_bool | np_ndarray_anyint,
22552279
) -> Series[int]: ...
22562280
@overload
22572281
def __rsub__(
2258-
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2282+
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
22592283
) -> Series[_T_COMPLEX]: ...
22602284
@overload
22612285
def __rsub__(self: Series[_T_INT], other: np_ndarray_float) -> Series[float]: ...
22622286
@overload
22632287
def __rsub__(
22642288
self: Series[float],
22652289
other: (
2266-
_T_INT
2267-
| Sequence[_T_INT]
2290+
int
2291+
| Sequence[int]
22682292
| np_ndarray_bool
22692293
| np_ndarray_anyint
22702294
| np_ndarray_float
2295+
| Series[_T_INT]
22712296
),
22722297
) -> Series[float]: ...
22732298
@overload
22742299
def __rsub__(
2275-
self: Series[float], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2300+
self: Series[float],
2301+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
22762302
) -> Series[_T_COMPLEX]: ...
22772303
@overload
22782304
def __rsub__(
22792305
self: Series[complex],
22802306
other: (
2281-
Sequence[_T_COMPLEX]
2307+
_T_COMPLEX
2308+
| Sequence[_T_COMPLEX]
22822309
| np_ndarray_bool
22832310
| np_ndarray_anyint
22842311
| np_ndarray_float
2312+
| Series[_T_COMPLEX]
22852313
),
22862314
) -> Series[complex]: ...
22872315
@overload
22882316
def __rsub__(
2289-
self: Series[_T_COMPLEX], other: np_ndarray_complex
2317+
self: Series[_T_COMPLEX], other: np_ndarray_complex | Series[complex]
22902318
) -> Series[complex]: ...
22912319
@overload
2292-
def __rsub__(self, other: S1) -> Self: ...
2293-
@overload
22942320
def rsub(
22952321
self: Series[Never],
2296-
other: Scalar | _ListLike | Series,
2322+
other: complex | _ListLike | Series,
22972323
level: Level | None = None,
22982324
fill_value: float | None = None,
22992325
axis: int = 0,
23002326
) -> Series: ...
23012327
@overload
23022328
def rsub(
23032329
self: Series[bool],
2304-
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
2330+
other: bool | Sequence[bool],
23052331
level: Level | None = None,
23062332
fill_value: float | None = None,
23072333
axis: int = 0,
2308-
) -> Series[_T_NUM_NON_BOOL]: ...
2334+
) -> Never: ...
23092335
@overload
23102336
def rsub(
23112337
self: Series[bool],
2312-
other: np_ndarray_anyint,
2338+
other: _T_COMPLEX | Sequence[_T_COMPLEX],
2339+
level: Level | None = None,
2340+
fill_value: float | None = None,
2341+
axis: int = 0,
2342+
) -> Series[_T_COMPLEX]: ...
2343+
@overload
2344+
def rsub(
2345+
self: Series[bool],
2346+
other: np_ndarray_anyint | Series[int],
23132347
level: Level | None = None,
23142348
fill_value: float | None = None,
23152349
axis: int = 0,
23162350
) -> Series[int]: ...
23172351
@overload
2352+
def rsub(
2353+
self: Series[bool],
2354+
other: np_ndarray_float | Series[float],
2355+
level: Level | None = None,
2356+
fill_value: float | None = None,
2357+
axis: int = 0,
2358+
) -> Series[float]: ...
2359+
@overload
23182360
def rsub(
23192361
self: Series[int],
23202362
other: (
@@ -2344,8 +2386,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
23442386
def rsub(
23452387
self: Series[float],
23462388
other: (
2347-
_T_INT
2348-
| Sequence[_T_INT]
2389+
int
2390+
| Sequence[int]
23492391
| np_ndarray_bool
23502392
| np_ndarray_anyint
23512393
| np_ndarray_float
@@ -2367,7 +2409,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
23672409
def rsub(
23682410
self: Series[complex],
23692411
other: (
2370-
Sequence[_T_COMPLEX]
2412+
_T_COMPLEX
2413+
| Sequence[_T_COMPLEX]
23712414
| np_ndarray_bool
23722415
| np_ndarray_anyint
23732416
| np_ndarray_float
@@ -2380,20 +2423,12 @@ class Series(IndexOpsMixin[S1], NDFrame):
23802423
@overload
23812424
def rsub(
23822425
self: Series[_T_COMPLEX],
2383-
other: np_ndarray_complex,
2426+
other: np_ndarray_complex | Series[complex],
23842427
level: Level | None = None,
23852428
fill_value: float | None = None,
23862429
axis: int = 0,
23872430
) -> Series[complex]: ...
23882431
@overload
2389-
def rsub(
2390-
self,
2391-
other: S1 | Series[S1],
2392-
level: Level | None = None,
2393-
fill_value: float | None = None,
2394-
axis: int = 0,
2395-
) -> Self: ...
2396-
@overload
23972432
def __truediv__(
23982433
self: Series[Never], other: complex | _ListLike | Series
23992434
) -> Series: ...
@@ -3248,7 +3283,7 @@ class TimestampSeries(Series[Timestamp]):
32483283
self, other: Timestamp | datetime | TimestampSeries
32493284
) -> TimedeltaSeries: ...
32503285
@overload
3251-
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
3286+
def __sub__(
32523287
self,
32533288
other: (
32543289
timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 | BaseOffset

0 commit comments

Comments
 (0)