Skip to content

Commit 7ac98f2

Browse files
authored
refactor(series)!: ⏱️ drop TimedeltaSeries (#1273)
* refactor: only drop TimestampSeries #1273 (review) * refactor: also remove TimedeltaSeries * feat: add * feat(test): sub * feat(test): mul * feat(test): truediv * feat(test): floordiv * feat(test): remove redundant * fix: pandas-dev/pandas#62316 * fix: comments * fix(test): ignore mypy for now * fix: comments * fix: comments
1 parent 2f63354 commit 7ac98f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3541
-964
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ minimum_pre_commit_version: 2.15.0
22
ci:
33
autofix_prs: false
44
repos:
5-
- repo: https://github.com/python/black
6-
rev: 25.1.0
5+
- repo: https://github.com/psf/black
6+
rev: 25.9.0
77
hooks:
88
- id: black
99
- repo: https://github.com/PyCQA/isort
1010
rev: 6.0.1
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.12.10
14+
rev: v0.13.2
1515
hooks:
1616
- id: ruff-check
1717
args: [

docs/philosophy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ revealed by `mypy` as follows:
5555
```text
5656
ttest.py:5: note: Revealed type is "pandas.core.series.Series[pandas._libs.tslibs.timestamps.Timestamp]"
5757
ttest.py:7: note: Revealed type is "pandas.core.series.Series[pandas._libs.tslibs.timestamps.Timestamp]"
58-
ttest.py:9: note: Revealed type is "pandas.core.series.TimedeltaSeries"
58+
ttest.py:9: note: Revealed type is "pandas.core.series.Series[pandas._libs.tslibs.timestamps.Timedelta]"
5959
ttest.py:10: error: Unsupported operand types for + ("Series[Timestamp]" and "Series[Timestamp]") [operator]
6060
```
6161

6262
The type `Series[Timestamp]` is the result of creating a series from `pd.to_datetime()`, while
63-
the type `TimedeltaSeries` is the result of subtracting two `Series[Timestamp]` as well as
63+
the type `Series[Timedelta]` is the result of subtracting two `Series[Timestamp]` as well as
6464
the result of `pd.to_timedelta()`.
6565

6666
### Progressive arithmetic typing for generic Series

pandas-stubs/_libs/interval.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ from pandas import (
1313
Timedelta,
1414
Timestamp,
1515
)
16-
from pandas.core.series import TimedeltaSeries
1716

1817
from pandas._typing import (
1918
IntervalClosedType,
@@ -173,7 +172,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
173172
@overload
174173
def __gt__(
175174
self,
176-
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
175+
other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta],
177176
) -> Series[bool]: ...
178177
@overload
179178
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
@@ -184,7 +183,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
184183
@overload
185184
def __lt__(
186185
self,
187-
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
186+
other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta],
188187
) -> Series[bool]: ...
189188
@overload
190189
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
@@ -195,7 +194,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
195194
@overload
196195
def __ge__(
197196
self,
198-
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
197+
other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta],
199198
) -> Series[bool]: ...
200199
@overload
201200
def __le__(self, other: Interval[_OrderableT]) -> bool: ...

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from pandas import (
1515
from pandas.core.series import (
1616
OffsetSeries,
1717
PeriodSeries,
18-
TimedeltaSeries,
1918
)
2019
from typing_extensions import TypeAlias
2120

@@ -86,7 +85,7 @@ class Period(PeriodMixin):
8685
@overload
8786
def __sub__(self, other: PeriodIndex) -> Index: ...
8887
@overload
89-
def __sub__(self, other: TimedeltaSeries) -> PeriodSeries: ...
88+
def __sub__(self, other: Series[Timedelta]) -> PeriodSeries: ...
9089
@overload
9190
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
9291
@overload
@@ -96,7 +95,7 @@ class Period(PeriodMixin):
9695
@overload
9796
def __add__(self, other: Index) -> PeriodIndex: ...
9897
@overload
99-
def __add__(self, other: OffsetSeries | TimedeltaSeries) -> PeriodSeries: ...
98+
def __add__(self, other: OffsetSeries | Series[Timedelta]) -> PeriodSeries: ...
10099
# ignore[misc] here because we know all other comparisons
101100
# are False, so we use Literal[False]
102101
@overload
@@ -172,7 +171,7 @@ class Period(PeriodMixin):
172171
@overload
173172
def __radd__(self, other: Index) -> Index: ...
174173
@overload
175-
def __radd__(self, other: TimedeltaSeries) -> PeriodSeries: ...
174+
def __radd__(self, other: Series[Timedelta]) -> PeriodSeries: ...
176175
@overload
177176
def __radd__(self, other: NaTType) -> NaTType: ...
178177
@property

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ from pandas import (
1717
Series,
1818
TimedeltaIndex,
1919
)
20-
from pandas.core.series import TimedeltaSeries
2120
from typing_extensions import (
2221
Self,
2322
TypeAlias,
@@ -162,10 +161,7 @@ class Timedelta(timedelta):
162161
@overload
163162
def __add__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
164163
@overload
165-
def __add__(
166-
self,
167-
other: TimedeltaSeries,
168-
) -> TimedeltaSeries: ...
164+
def __add__(self, other: Series[Timedelta]) -> Series[Timedelta]: ...
169165
@overload
170166
def __add__(self, other: Series[Timestamp]) -> Series[Timestamp]: ...
171167
@overload
@@ -198,9 +194,7 @@ class Timedelta(timedelta):
198194
@overload
199195
def __sub__(self, other: pd.TimedeltaIndex) -> TimedeltaIndex: ...
200196
@overload
201-
def __sub__(
202-
self, other: TimedeltaSeries | Series[pd.Timedelta]
203-
) -> TimedeltaSeries: ...
197+
def __sub__(self, other: Series[pd.Timedelta]) -> Series[pd.Timedelta]: ...
204198
@overload
205199
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
206200
@overload
@@ -234,9 +228,9 @@ class Timedelta(timedelta):
234228
self, other: np_ndarray[ShapeT, np.integer] | np_ndarray[ShapeT, np.floating]
235229
) -> np_ndarray[ShapeT, np.timedelta64]: ...
236230
@overload
237-
def __mul__(self, other: Series[int]) -> TimedeltaSeries: ...
231+
def __mul__(self, other: Series[int]) -> Series[Timedelta]: ...
238232
@overload
239-
def __mul__(self, other: Series[float]) -> TimedeltaSeries: ...
233+
def __mul__(self, other: Series[float]) -> Series[Timedelta]: ...
240234
@overload
241235
def __mul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
242236
@overload
@@ -246,9 +240,9 @@ class Timedelta(timedelta):
246240
self, other: np_ndarray[ShapeT, np.floating] | np_ndarray[ShapeT, np.integer]
247241
) -> np_ndarray[ShapeT, np.timedelta64]: ...
248242
@overload
249-
def __rmul__(self, other: Series[int]) -> TimedeltaSeries: ...
243+
def __rmul__(self, other: Series[int]) -> Series[Timedelta]: ...
250244
@overload
251-
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
245+
def __rmul__(self, other: Series[float]) -> Series[Timedelta]: ...
252246
# maybe related to https://github.com/python/mypy/issues/10755
253247
@overload
254248
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
@@ -269,11 +263,11 @@ class Timedelta(timedelta):
269263
@overload
270264
def __floordiv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
271265
@overload
272-
def __floordiv__(self, other: Series[int]) -> TimedeltaSeries: ...
266+
def __floordiv__(self, other: Series[int]) -> Series[Timedelta]: ...
273267
@overload
274-
def __floordiv__(self, other: Series[float]) -> TimedeltaSeries: ...
268+
def __floordiv__(self, other: Series[float]) -> Series[Timedelta]: ...
275269
@overload
276-
def __floordiv__(self, other: TimedeltaSeries) -> Series[int]: ...
270+
def __floordiv__(self, other: Series[Timedelta]) -> Series[int]: ...
277271
@overload
278272
def __floordiv__(self, other: NaTType | None) -> float: ...
279273
@overload
@@ -294,19 +288,19 @@ class Timedelta(timedelta):
294288
self, other: np_ndarray[ShapeT, np.integer] | np_ndarray[ShapeT, np.floating]
295289
) -> np_ndarray[ShapeT, np.timedelta64]: ...
296290
@overload
297-
def __truediv__(self, other: TimedeltaSeries) -> Series[float]: ...
291+
def __truediv__(self, other: Series[Timedelta]) -> Series[float]: ...
298292
@overload
299-
def __truediv__(self, other: Series[int]) -> TimedeltaSeries: ...
293+
def __truediv__(self, other: Series[int]) -> Series[Timedelta]: ...
300294
@overload
301-
def __truediv__(self, other: Series[float]) -> TimedeltaSeries: ...
295+
def __truediv__(self, other: Series[float]) -> Series[Timedelta]: ...
302296
@overload
303297
def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
304298
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
305299
# Override due to more types supported than dt.timedelta
306300
@overload
307301
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
308302
@overload
309-
def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
303+
def __eq__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
310304
@overload
311305
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
312306
@overload
@@ -319,7 +313,7 @@ class Timedelta(timedelta):
319313
@overload
320314
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
321315
@overload
322-
def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
316+
def __ne__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
323317
@overload
324318
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
325319
@overload
@@ -334,7 +328,7 @@ class Timedelta(timedelta):
334328
@overload
335329
def __mod__(self, other: float) -> Timedelta: ...
336330
@overload
337-
def __mod__(self, other: Series[int] | Series[float]) -> TimedeltaSeries: ...
331+
def __mod__(self, other: Series[int] | Series[float]) -> Series[Timedelta]: ...
338332
@overload
339333
def __mod__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
340334
@overload
@@ -343,8 +337,8 @@ class Timedelta(timedelta):
343337
) -> np_ndarray[ShapeT, np.timedelta64]: ...
344338
@overload
345339
def __mod__(
346-
self, other: Series[int] | Series[float] | TimedeltaSeries
347-
) -> TimedeltaSeries: ...
340+
self, other: Series[int] | Series[float] | Series[Timedelta]
341+
) -> Series[Timedelta]: ...
348342
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
349343
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
350344
# for le, lt ge and gt
@@ -358,7 +352,7 @@ class Timedelta(timedelta):
358352
self, other: np_ndarray[ShapeT, np.timedelta64]
359353
) -> np_ndarray[ShapeT, np.bool_]: ...
360354
@overload
361-
def __le__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
355+
def __le__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
362356
# Override due to more types supported than dt.timedelta
363357
@overload # type: ignore[override]
364358
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@@ -369,7 +363,7 @@ class Timedelta(timedelta):
369363
self, other: np_ndarray[ShapeT, np.timedelta64]
370364
) -> np_ndarray[ShapeT, np.bool_]: ...
371365
@overload
372-
def __lt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
366+
def __lt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
373367
# Override due to more types supported than dt.timedelta
374368
@overload # type: ignore[override]
375369
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@@ -380,7 +374,7 @@ class Timedelta(timedelta):
380374
self, other: np_ndarray[ShapeT, np.timedelta64]
381375
) -> np_ndarray[ShapeT, np.bool_]: ...
382376
@overload
383-
def __ge__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
377+
def __ge__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
384378
# Override due to more types supported than dt.timedelta
385379
@overload # type: ignore[override]
386380
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@@ -391,7 +385,7 @@ class Timedelta(timedelta):
391385
self, other: np_ndarray[ShapeT, np.timedelta64]
392386
) -> np_ndarray[ShapeT, np.bool_]: ...
393387
@overload
394-
def __gt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
388+
def __gt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
395389
def __hash__(self) -> int: ...
396390
def isoformat(self) -> str: ...
397391
def to_numpy(self) -> np.timedelta64: ...

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ from pandas import (
2222
TimedeltaIndex,
2323
)
2424
from pandas.core.indexes.base import Index
25-
from pandas.core.series import (
26-
Series,
27-
TimedeltaSeries,
28-
)
25+
from pandas.core.series import Series
2926
from typing_extensions import (
3027
Never,
3128
Self,
@@ -225,8 +222,6 @@ class Timestamp(datetime, SupportsIndex):
225222
@overload
226223
def __add__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
227224
@overload
228-
def __add__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
229-
@overload
230225
def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
231226
@overload
232227
def __radd__(self, other: timedelta) -> Self: ...
@@ -244,8 +239,6 @@ class Timestamp(datetime, SupportsIndex):
244239
@overload
245240
def __sub__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
246241
@overload
247-
def __sub__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
248-
@overload
249242
def __sub__(
250243
self, other: np_ndarray[ShapeT, np.timedelta64]
251244
) -> np_ndarray[ShapeT, np.datetime64]: ...

pandas-stubs/core/arraylike.pyi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ class OpsMixin:
1919
def __rxor__(self, other: Any) -> Self: ...
2020
# -------------------------------------------------------------
2121
# Arithmetic Methods
22-
def __mul__(self, other: Any) -> Self: ...
23-
def __rmul__(self, other: Any) -> Self: ...
24-
# Handled by subclasses that specify only the valid values
25-
# that can be passed
26-
# def __truediv__(self, other: Any) -> Self: ...
27-
# def __rtruediv__(self, other: Any) -> Self: ...
28-
# def __floordiv__(self, other: Any) -> Self: ...
29-
# def __rfloordiv__(self, other: Any) -> Self: ...
3022
def __mod__(self, other: Any) -> Self: ...
3123
def __rmod__(self, other: Any) -> Self: ...
3224
def __divmod__(self, other: Any) -> tuple[Self, Self]: ...

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
763763
@overload
764764
def to_xml(
765765
self,
766-
path_or_buffer: Literal[None] = ...,
766+
path_or_buffer: None = ...,
767767
index: bool = ...,
768768
root_name: str | None = ...,
769769
row_name: str | None = ...,
@@ -1806,6 +1806,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
18061806
level: Level | None = ...,
18071807
fill_value: float | None = None,
18081808
) -> Self: ...
1809+
def __mul__(self, other: Any) -> Self: ...
1810+
def __rmul__(self, other: Any) -> Self: ...
18091811
@final
18101812
def add_prefix(self, prefix: _str, axis: Axis | None = None) -> Self: ...
18111813
@final

pandas-stubs/core/groupby/indexing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class GroupByNthSelector(Generic[_GroupByT]):
2727
def __call__(
2828
self,
2929
n: PositionalIndexer | tuple,
30-
dropna: Literal["any", "all", None] = ...,
30+
dropna: Literal["any", "all"] | None = ...,
3131
) -> DataFrame | Series: ...
3232
def __getitem__(self, n: PositionalIndexer | tuple) -> DataFrame | Series: ...

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ from pandas.core.frame import DataFrame
3030
from pandas.core.series import (
3131
PeriodSeries,
3232
Series,
33-
TimedeltaSeries,
3433
)
3534
from typing_extensions import Never
3635

@@ -165,7 +164,11 @@ class _DatetimeLikeOps(
165164

166165
_DTTimestampTimedeltaReturnType = TypeVar(
167166
"_DTTimestampTimedeltaReturnType",
168-
bound=Series | Series[Timestamp] | TimedeltaSeries | DatetimeIndex | TimedeltaIndex,
167+
bound=Series
168+
| Series[Timestamp]
169+
| Series[Timedelta]
170+
| DatetimeIndex
171+
| TimedeltaIndex,
169172
)
170173

171174
class _DatetimeRoundingMethods(Generic[_DTTimestampTimedeltaReturnType]):
@@ -316,7 +319,7 @@ class _TimedeltaPropertiesNoRounding(
316319
class TimedeltaProperties(
317320
Properties,
318321
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
319-
_DatetimeRoundingMethods[TimedeltaSeries],
322+
_DatetimeRoundingMethods[Series[Timedelta]],
320323
):
321324
@property
322325
def unit(self) -> TimeUnit: ...
@@ -440,7 +443,7 @@ class _dtDescriptor(CombinedDatetimelikeProperties, Generic[S1]):
440443
) -> TimestampProperties: ...
441444
@overload
442445
def __get__(
443-
self, instance: Series[Timedelta] | TimedeltaSeries, owner: Any
446+
self, instance: Series[Timedelta], owner: Any
444447
) -> TimedeltaProperties: ...
445448
@overload
446449
def __get__(

0 commit comments

Comments
 (0)