Skip to content

Commit 1bcf162

Browse files
committed
feat: arithmetic sub
1 parent e6b97c1 commit 1bcf162

File tree

6 files changed

+711
-32
lines changed

6 files changed

+711
-32
lines changed

pandas-stubs/core/series.pyi

Lines changed: 252 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
20712071
) -> Series[bool]: ...
20722072
@overload
20732073
def __ror__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
2074-
def __rsub__(self, other: num | _ListLike | Series[S1]) -> Series: ...
20752074
# ignore needed for mypy as we want different results based on the arguments
20762075
@overload # type: ignore[override]
20772076
def __rxor__( # pyright: ignore[reportOverlappingOverload]
@@ -2080,6 +2079,47 @@ class Series(IndexOpsMixin[S1], NDFrame):
20802079
@overload
20812080
def __rxor__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
20822081
@overload
2082+
def __sub__(
2083+
self, other: Timestamp | datetime | TimestampSeries
2084+
) -> TimedeltaSeries: ...
2085+
@overload
2086+
def __sub__(self: Series[Never], other: complex | _ListLike | Series) -> Series: ...
2087+
@overload
2088+
def __sub__(self, other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
2089+
@overload
2090+
def __sub__(
2091+
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
2092+
) -> Series[_T_COMPLEX]: ...
2093+
@overload
2094+
def __sub__(self: Series[int], other: np_ndarray_anyint) -> Series[int]: ...
2095+
@overload
2096+
def __sub__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
2097+
@overload
2098+
def __sub__(self: Series[int], other: np_ndarray_complex) -> Series[complex]: ...
2099+
@overload
2100+
def __sub__(
2101+
self: Series[float],
2102+
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2103+
) -> Series[float]: ...
2104+
@overload
2105+
def __sub__(
2106+
self: Series[float],
2107+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2108+
) -> Series[_T_COMPLEX]: ...
2109+
@overload
2110+
def __sub__(self: Series[float], other: np_ndarray_complex) -> Series[complex]: ...
2111+
@overload
2112+
def __sub__(
2113+
self: Series[complex],
2114+
other: (
2115+
Sequence[_T_COMPLEX]
2116+
| Series[_T_COMPLEX]
2117+
| np_ndarray_anyint
2118+
| np_ndarray_float
2119+
| np_ndarray_complex
2120+
),
2121+
) -> Series[complex]: ...
2122+
@overload
20832123
def __sub__(
20842124
self: Series[Timestamp],
20852125
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
@@ -2090,14 +2130,217 @@ class Series(IndexOpsMixin[S1], NDFrame):
20902130
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
20912131
) -> TimedeltaSeries: ...
20922132
@overload
2093-
def __sub__(
2094-
self, other: Timestamp | datetime | TimestampSeries
2095-
) -> TimedeltaSeries: ...
2133+
def __sub__(self, other: S1 | Series[S1]) -> Self: ...
2134+
@overload
2135+
def sub(
2136+
self: Series[Never],
2137+
other: Scalar | _ListLike | Series,
2138+
level: Level | None = None,
2139+
fill_value: float | None = None,
2140+
axis: int = 0,
2141+
) -> Series: ...
2142+
@overload
2143+
def sub(
2144+
self: Series[int],
2145+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2146+
level: Level | None = None,
2147+
fill_value: float | None = None,
2148+
axis: int = 0,
2149+
) -> Series[_T_COMPLEX]: ...
2150+
@overload
2151+
def sub(
2152+
self: Series[int],
2153+
other: np_ndarray_anyint,
2154+
level: Level | None = None,
2155+
fill_value: float | None = None,
2156+
axis: int = 0,
2157+
) -> Series[int]: ...
2158+
@overload
2159+
def sub(
2160+
self: Series[int],
2161+
other: np_ndarray_float,
2162+
level: Level | None = None,
2163+
fill_value: float | None = None,
2164+
axis: int = 0,
2165+
) -> Series[float]: ...
2166+
@overload
2167+
def sub(
2168+
self: Series[int],
2169+
other: np_ndarray_complex,
2170+
level: Level | None = None,
2171+
fill_value: float | None = None,
2172+
axis: int = 0,
2173+
) -> Series[complex]: ...
2174+
@overload
2175+
def sub(
2176+
self: Series[float],
2177+
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2178+
level: Level | None = None,
2179+
fill_value: float | None = None,
2180+
axis: int = 0,
2181+
) -> Series[float]: ...
2182+
@overload
2183+
def sub(
2184+
self: Series[float],
2185+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2186+
level: Level | None = None,
2187+
fill_value: float | None = None,
2188+
axis: int = 0,
2189+
) -> Series[_T_COMPLEX]: ...
2190+
@overload
2191+
def sub(
2192+
self: Series[float],
2193+
other: np_ndarray_complex,
2194+
level: Level | None = None,
2195+
fill_value: float | None = None,
2196+
axis: int = 0,
2197+
) -> Series[complex]: ...
2198+
@overload
2199+
def sub(
2200+
self: Series[complex],
2201+
other: (
2202+
Sequence[_T_COMPLEX]
2203+
| np_ndarray_anyint
2204+
| np_ndarray_float
2205+
| np_ndarray_complex
2206+
| Series[_T_COMPLEX]
2207+
),
2208+
level: Level | None = None,
2209+
fill_value: float | None = None,
2210+
axis: int = 0,
2211+
) -> Series[complex]: ...
2212+
@overload
2213+
def sub(
2214+
self,
2215+
other: S1 | Series[S1],
2216+
level: Level | None = None,
2217+
fill_value: float | None = None,
2218+
axis: int = 0,
2219+
) -> Self: ...
2220+
@overload
2221+
def __rsub__(self: Series[Never], other: Scalar | _ListLike) -> Series: ...
2222+
@overload
2223+
def __rsub__(
2224+
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2225+
) -> Series[_T_COMPLEX]: ...
20962226
@overload
2097-
def __sub__(self, other: num | _ListLike | Series) -> Series: ...
2227+
def __rsub__(self: Series[int], other: np_ndarray_anyint) -> Series[int]: ...
2228+
@overload
2229+
def __rsub__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
2230+
@overload
2231+
def __rsub__(self: Series[int], other: np_ndarray_complex) -> Series[complex]: ...
2232+
@overload
2233+
def __rsub__(
2234+
self: Series[float],
2235+
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float,
2236+
) -> Series[float]: ...
2237+
@overload
2238+
def __rsub__(
2239+
self: Series[float], other: _T_COMPLEX | Sequence[_T_COMPLEX]
2240+
) -> Series[_T_COMPLEX]: ...
2241+
@overload
2242+
def __rsub__(self: Series[float], other: np_ndarray_complex) -> Series[complex]: ...
2243+
@overload
2244+
def __rsub__(
2245+
self: Series[complex],
2246+
other: (
2247+
np_ndarray_anyint
2248+
| np_ndarray_float
2249+
| np_ndarray_complex
2250+
| Sequence[_T_COMPLEX]
2251+
),
2252+
) -> Series[complex]: ...
2253+
@overload
2254+
def __rsub__(self, other: S1) -> Self: ...
2255+
@overload
2256+
def rsub(
2257+
self: Series[Never],
2258+
other: Scalar | _ListLike | Series,
2259+
level: Level | None = None,
2260+
fill_value: float | None = None,
2261+
axis: int = 0,
2262+
) -> Series: ...
2263+
@overload
2264+
def rsub(
2265+
self: Series[int],
2266+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2267+
level: Level | None = None,
2268+
fill_value: float | None = None,
2269+
axis: int = 0,
2270+
) -> Series[_T_COMPLEX]: ...
2271+
@overload
2272+
def rsub(
2273+
self: Series[int],
2274+
other: np_ndarray_anyint,
2275+
level: Level | None = None,
2276+
fill_value: float | None = None,
2277+
axis: int = 0,
2278+
) -> Series[int]: ...
2279+
@overload
2280+
def rsub(
2281+
self: Series[int],
2282+
other: np_ndarray_float,
2283+
level: Level | None = None,
2284+
fill_value: float | None = None,
2285+
axis: int = 0,
2286+
) -> Series[float]: ...
2287+
@overload
2288+
def rsub(
2289+
self: Series[int],
2290+
other: np_ndarray_complex,
2291+
level: Level | None = None,
2292+
fill_value: float | None = None,
2293+
axis: int = 0,
2294+
) -> Series[complex]: ...
2295+
@overload
2296+
def rsub(
2297+
self: Series[float],
2298+
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2299+
level: Level | None = None,
2300+
fill_value: float | None = None,
2301+
axis: int = 0,
2302+
) -> Series[float]: ...
2303+
@overload
2304+
def rsub(
2305+
self: Series[float],
2306+
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
2307+
level: Level | None = None,
2308+
fill_value: float | None = None,
2309+
axis: int = 0,
2310+
) -> Series[_T_COMPLEX]: ...
2311+
@overload
2312+
def rsub(
2313+
self: Series[float],
2314+
other: np_ndarray_complex,
2315+
level: Level | None = None,
2316+
fill_value: float | None = None,
2317+
axis: int = 0,
2318+
) -> Series[complex]: ...
2319+
@overload
2320+
def rsub(
2321+
self: Series[complex],
2322+
other: (
2323+
Sequence[_T_COMPLEX]
2324+
| np_ndarray_anyint
2325+
| np_ndarray_float
2326+
| np_ndarray_complex
2327+
| Series[_T_COMPLEX]
2328+
),
2329+
level: Level | None = None,
2330+
fill_value: float | None = None,
2331+
axis: int = 0,
2332+
) -> Series[complex]: ...
2333+
@overload
2334+
def rsub(
2335+
self,
2336+
other: S1 | Series[S1],
2337+
level: Level | None = None,
2338+
fill_value: float | None = None,
2339+
axis: int = 0,
2340+
) -> Self: ...
20982341
@overload
20992342
def __truediv__(
2100-
self: Series[Never], other: Scalar | _ListLike | Series
2343+
self: Series[Never], other: complex | _ListLike | Series
21012344
) -> Series: ...
21022345
@overload
21032346
def __truediv__(self, other: Series[Never]) -> Series: ...
@@ -2145,7 +2388,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
21452388
@overload
21462389
def truediv(
21472390
self: Series[Never],
2148-
other: Scalar | _ListLike | Series,
2391+
other: complex | _ListLike | Series,
21492392
level: Level | None = None,
21502393
fill_value: float | None = None,
21512394
axis: AxisIndex = 0,
@@ -2231,7 +2474,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
22312474
) -> Series: ...
22322475
div = truediv
22332476
@overload
2234-
def __rtruediv__(self: Series[Never], other: Scalar | _ListLike) -> Series: ...
2477+
def __rtruediv__(self: Series[Never], other: complex | _ListLike) -> Series: ...
22352478
@overload
22362479
def __rtruediv__(
22372480
self: Series[int],
@@ -2274,7 +2517,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
22742517
@overload
22752518
def rtruediv(
22762519
self: Series[Never],
2277-
other: Scalar | _ListLike | Series,
2520+
other: complex | _ListLike | Series,
22782521
level: Level | None = None,
22792522
fill_value: float | None = None,
22802523
axis: AxisIndex = 0,
@@ -2675,13 +2918,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
26752918
fill_value: float | None = None,
26762919
axis: AxisIndex = ...,
26772920
) -> Series[S1]: ...
2678-
def rsub(
2679-
self,
2680-
other: Series[S1] | Scalar,
2681-
level: Level | None = ...,
2682-
fill_value: float | None = None,
2683-
axis: AxisIndex = ...,
2684-
) -> Series[S1]: ...
26852921
def sem(
26862922
self,
26872923
axis: AxisIndex | None = 0,
@@ -2705,20 +2941,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
27052941
numeric_only: _bool = False,
27062942
**kwargs: Any,
27072943
) -> float: ...
2708-
def sub(
2709-
self,
2710-
other: num | _ListLike | Series[S1],
2711-
level: Level | None = ...,
2712-
fill_value: float | None = None,
2713-
axis: AxisIndex | None = 0,
2714-
) -> Series[S1]: ...
2715-
def subtract(
2716-
self,
2717-
other: num | _ListLike | Series[S1],
2718-
level: Level | None = ...,
2719-
fill_value: float | None = None,
2720-
axis: AxisIndex | None = 0,
2721-
) -> Series[S1]: ...
27222944
@overload
27232945
def sum(
27242946
self: Series[Never],

0 commit comments

Comments
 (0)