@@ -188,6 +188,7 @@ from pandas.core.dtypes.dtypes import CategoricalDtype
188
188
189
189
from pandas .plotting import PlotAccessor
190
190
191
+ _T_NUM_NON_BOOL = TypeVar ("_T_NUM_NON_BOOL" , int , float , complex )
191
192
_T_INT = TypeVar ("_T_INT" , bound = int )
192
193
_T_COMPLEX = TypeVar ("_T_COMPLEX" , bound = complex )
193
194
@@ -2087,39 +2088,60 @@ class Series(IndexOpsMixin[S1], NDFrame):
2087
2088
@overload
2088
2089
def __sub__ (self , other : Series [Never ]) -> Series : ... # type: ignore[overload-overlap]
2089
2090
@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
2090
2107
def __sub__ (
2091
2108
self : Series [int ], other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ]
2092
2109
) -> Series [_T_COMPLEX ]: ...
2093
2110
@overload
2094
- def __sub__ (self : Series [int ], other : np_ndarray_anyint ) -> Series [int ]: ...
2095
- @overload
2096
2111
def __sub__ (self : Series [int ], other : np_ndarray_float ) -> Series [float ]: ...
2097
2112
@overload
2098
- def __sub__ (self : Series [int ], other : np_ndarray_complex ) -> Series [complex ]: ...
2099
- @overload
2100
2113
def __sub__ (
2101
2114
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
+ ),
2103
2123
) -> Series [float ]: ...
2104
2124
@overload
2105
2125
def __sub__ (
2106
2126
self : Series [float ],
2107
2127
other : _T_COMPLEX | Sequence [_T_COMPLEX ] | Series [_T_COMPLEX ],
2108
2128
) -> Series [_T_COMPLEX ]: ...
2109
2129
@overload
2110
- def __sub__ (self : Series [float ], other : np_ndarray_complex ) -> Series [complex ]: ...
2111
- @overload
2112
2130
def __sub__ (
2113
2131
self : Series [complex ],
2114
2132
other : (
2115
2133
Sequence [_T_COMPLEX ]
2116
- | Series [ _T_COMPLEX ]
2134
+ | np_ndarray_bool
2117
2135
| np_ndarray_anyint
2118
2136
| np_ndarray_float
2119
- | np_ndarray_complex
2137
+ | Series [ _T_COMPLEX ]
2120
2138
),
2121
2139
) -> Series [complex ]: ...
2122
2140
@overload
2141
+ def __sub__ (
2142
+ self : Series [_T_COMPLEX ], other : np_ndarray_complex
2143
+ ) -> Series [complex ]: ...
2144
+ @overload
2123
2145
def __sub__ (
2124
2146
self : Series [Timestamp ],
2125
2147
other : Timedelta | TimedeltaSeries | TimedeltaIndex | np .timedelta64 ,
@@ -2134,22 +2156,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
2134
2156
@overload
2135
2157
def sub (
2136
2158
self : Series [Never ],
2137
- other : Scalar | _ListLike | Series ,
2159
+ other : complex | _ListLike | Series ,
2138
2160
level : Level | None = None ,
2139
2161
fill_value : float | None = None ,
2140
2162
axis : int = 0 ,
2141
2163
) -> Series : ...
2142
2164
@overload
2143
2165
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 ],
2146
2168
level : Level | None = None ,
2147
2169
fill_value : float | None = None ,
2148
2170
axis : int = 0 ,
2149
- ) -> Series [_T_COMPLEX ]: ...
2171
+ ) -> Series [_T_NUM_NON_BOOL ]: ...
2150
2172
@overload
2151
2173
def sub (
2152
- self : Series [int ],
2174
+ self : Series [bool ],
2153
2175
other : np_ndarray_anyint ,
2154
2176
level : Level | None = None ,
2155
2177
fill_value : float | None = None ,
@@ -2158,58 +2180,75 @@ class Series(IndexOpsMixin[S1], NDFrame):
2158
2180
@overload
2159
2181
def sub (
2160
2182
self : Series [int ],
2161
- other : np_ndarray_float ,
2183
+ other : (
2184
+ bool | Sequence [bool ] | np_ndarray_bool | np_ndarray_anyint | Series [bool ]
2185
+ ),
2162
2186
level : Level | None = None ,
2163
2187
fill_value : float | None = None ,
2164
2188
axis : int = 0 ,
2165
- ) -> Series [float ]: ...
2189
+ ) -> Series [int ]: ...
2166
2190
@overload
2167
2191
def sub (
2168
2192
self : Series [int ],
2169
- other : np_ndarray_complex ,
2193
+ other : _T_COMPLEX | Sequence [ _T_COMPLEX ] | Series [ _T_COMPLEX ] ,
2170
2194
level : Level | None = None ,
2171
2195
fill_value : float | None = None ,
2172
2196
axis : int = 0 ,
2173
- ) -> Series [complex ]: ...
2197
+ ) -> Series [_T_COMPLEX ]: ...
2174
2198
@overload
2175
2199
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 ,
2178
2202
level : Level | None = None ,
2179
2203
fill_value : float | None = None ,
2180
2204
axis : int = 0 ,
2181
2205
) -> Series [float ]: ...
2182
2206
@overload
2183
2207
def sub (
2184
2208
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
+ ),
2186
2217
level : Level | None = None ,
2187
2218
fill_value : float | None = None ,
2188
2219
axis : int = 0 ,
2189
- ) -> Series [_T_COMPLEX ]: ...
2220
+ ) -> Series [float ]: ...
2190
2221
@overload
2191
2222
def sub (
2192
2223
self : Series [float ],
2193
- other : np_ndarray_complex ,
2224
+ other : _T_COMPLEX | Sequence [ _T_COMPLEX ] | Series [ _T_COMPLEX ] ,
2194
2225
level : Level | None = None ,
2195
2226
fill_value : float | None = None ,
2196
2227
axis : int = 0 ,
2197
- ) -> Series [complex ]: ...
2228
+ ) -> Series [_T_COMPLEX ]: ...
2198
2229
@overload
2199
2230
def sub (
2200
2231
self : Series [complex ],
2201
2232
other : (
2202
2233
Sequence [_T_COMPLEX ]
2234
+ | np_ndarray_bool
2203
2235
| np_ndarray_anyint
2204
2236
| np_ndarray_float
2205
- | np_ndarray_complex
2206
2237
| Series [_T_COMPLEX ]
2207
2238
),
2208
2239
level : Level | None = None ,
2209
2240
fill_value : float | None = None ,
2210
2241
axis : int = 0 ,
2211
2242
) -> Series [complex ]: ...
2212
2243
@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
2213
2252
def sub (
2214
2253
self ,
2215
2254
other : S1 | Series [S1 ],
@@ -2218,39 +2257,54 @@ class Series(IndexOpsMixin[S1], NDFrame):
2218
2257
axis : int = 0 ,
2219
2258
) -> Self : ...
2220
2259
@overload
2221
- def __rsub__ (self : Series [Never ], other : Scalar | _ListLike ) -> Series : ...
2260
+ def __rsub__ (self : Series [Never ], other : complex | _ListLike ) -> Series : ...
2222
2261
@overload
2223
2262
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 ]: ...
2226
2265
@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 ]: ...
2228
2267
@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 ]: ...
2230
2272
@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 ]: ...
2232
2278
@overload
2233
2279
def __rsub__ (
2234
2280
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
+ ),
2236
2288
) -> Series [float ]: ...
2237
2289
@overload
2238
2290
def __rsub__ (
2239
2291
self : Series [float ], other : _T_COMPLEX | Sequence [_T_COMPLEX ]
2240
2292
) -> Series [_T_COMPLEX ]: ...
2241
2293
@overload
2242
- def __rsub__ (self : Series [float ], other : np_ndarray_complex ) -> Series [complex ]: ...
2243
- @overload
2244
2294
def __rsub__ (
2245
2295
self : Series [complex ],
2246
2296
other : (
2247
- np_ndarray_anyint
2297
+ Sequence [_T_COMPLEX ]
2298
+ | np_ndarray_bool
2299
+ | np_ndarray_anyint
2248
2300
| np_ndarray_float
2249
- | np_ndarray_complex
2250
- | Sequence [_T_COMPLEX ]
2251
2301
),
2252
2302
) -> Series [complex ]: ...
2253
2303
@overload
2304
+ def __rsub__ (
2305
+ self : Series [_T_COMPLEX ], other : np_ndarray_complex
2306
+ ) -> Series [complex ]: ...
2307
+ @overload
2254
2308
def __rsub__ (self , other : S1 ) -> Self : ...
2255
2309
@overload
2256
2310
def rsub (
@@ -2262,15 +2316,15 @@ class Series(IndexOpsMixin[S1], NDFrame):
2262
2316
) -> Series : ...
2263
2317
@overload
2264
2318
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 ],
2267
2321
level : Level | None = None ,
2268
2322
fill_value : float | None = None ,
2269
2323
axis : int = 0 ,
2270
- ) -> Series [_T_COMPLEX ]: ...
2324
+ ) -> Series [_T_NUM_NON_BOOL ]: ...
2271
2325
@overload
2272
2326
def rsub (
2273
- self : Series [int ],
2327
+ self : Series [bool ],
2274
2328
other : np_ndarray_anyint ,
2275
2329
level : Level | None = None ,
2276
2330
fill_value : float | None = None ,
@@ -2279,58 +2333,75 @@ class Series(IndexOpsMixin[S1], NDFrame):
2279
2333
@overload
2280
2334
def rsub (
2281
2335
self : Series [int ],
2282
- other : np_ndarray_float ,
2336
+ other : (
2337
+ bool | Sequence [bool ] | np_ndarray_bool | np_ndarray_anyint | Series [bool ]
2338
+ ),
2283
2339
level : Level | None = None ,
2284
2340
fill_value : float | None = None ,
2285
2341
axis : int = 0 ,
2286
- ) -> Series [float ]: ...
2342
+ ) -> Series [int ]: ...
2287
2343
@overload
2288
2344
def rsub (
2289
2345
self : Series [int ],
2290
- other : np_ndarray_complex ,
2346
+ other : _T_COMPLEX | Sequence [ _T_COMPLEX ] | Series [ _T_COMPLEX ] ,
2291
2347
level : Level | None = None ,
2292
2348
fill_value : float | None = None ,
2293
2349
axis : int = 0 ,
2294
- ) -> Series [complex ]: ...
2350
+ ) -> Series [_T_COMPLEX ]: ...
2295
2351
@overload
2296
2352
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 ,
2299
2355
level : Level | None = None ,
2300
2356
fill_value : float | None = None ,
2301
2357
axis : int = 0 ,
2302
2358
) -> Series [float ]: ...
2303
2359
@overload
2304
2360
def rsub (
2305
2361
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
+ ),
2307
2370
level : Level | None = None ,
2308
2371
fill_value : float | None = None ,
2309
2372
axis : int = 0 ,
2310
- ) -> Series [_T_COMPLEX ]: ...
2373
+ ) -> Series [float ]: ...
2311
2374
@overload
2312
2375
def rsub (
2313
2376
self : Series [float ],
2314
- other : np_ndarray_complex ,
2377
+ other : _T_COMPLEX | Sequence [ _T_COMPLEX ] | Series [ _T_COMPLEX ] ,
2315
2378
level : Level | None = None ,
2316
2379
fill_value : float | None = None ,
2317
2380
axis : int = 0 ,
2318
- ) -> Series [complex ]: ...
2381
+ ) -> Series [_T_COMPLEX ]: ...
2319
2382
@overload
2320
2383
def rsub (
2321
2384
self : Series [complex ],
2322
2385
other : (
2323
2386
Sequence [_T_COMPLEX ]
2387
+ | np_ndarray_bool
2324
2388
| np_ndarray_anyint
2325
2389
| np_ndarray_float
2326
- | np_ndarray_complex
2327
2390
| Series [_T_COMPLEX ]
2328
2391
),
2329
2392
level : Level | None = None ,
2330
2393
fill_value : float | None = None ,
2331
2394
axis : int = 0 ,
2332
2395
) -> Series [complex ]: ...
2333
2396
@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
2334
2405
def rsub (
2335
2406
self ,
2336
2407
other : S1 | Series [S1 ],
0 commit comments