Skip to content

Commit 6caa0c8

Browse files
committed
refactor: also remove TimedeltaSeries
1 parent 41c7015 commit 6caa0c8

File tree

14 files changed

+293
-387
lines changed

14 files changed

+293
-387
lines changed

docs/philosophy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ revealed as follows:
5656
```text
5757
ttest.py:4: note: Revealed type is "pandas.core.series.Series[pandas._libs.tslibs.timestamps.Timestamp]"
5858
ttest.py:6: note: Revealed type is "pandas.core.series.Series[pandas._libs.tslibs.timestamps.Timestamp]"
59-
ttest.py:8: note: Revealed type is "pandas.core.series.TimedeltaSeries"
59+
ttest.py:8: note: Revealed type is "pandas.core.series.Series[pandas._libs.tslibs.timedeltas.Timedelta]"
6060
ttest.py:9: error: Need type annotation for "ssum" [var-annotated]
6161
ttest.py:10: note: Revealed type is "Never"
6262
```
6363

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

6868
### Interval is Generic

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,
@@ -171,7 +170,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
171170
@overload
172171
def __gt__(
173172
self,
174-
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
173+
other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta],
175174
) -> Series[bool]: ...
176175
@overload
177176
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
@@ -180,7 +179,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
180179
@overload
181180
def __lt__(
182181
self,
183-
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
182+
other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta],
184183
) -> Series[bool]: ...
185184
@overload
186185
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
@@ -189,7 +188,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
189188
@overload
190189
def __ge__(
191190
self,
192-
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
191+
other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta],
193192
) -> Series[bool]: ...
194193
@overload
195194
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

@@ -82,7 +81,7 @@ class Period(PeriodMixin):
8281
@overload
8382
def __sub__(self, other: PeriodIndex) -> Index: ...
8483
@overload
85-
def __sub__(self, other: TimedeltaSeries) -> PeriodSeries: ...
84+
def __sub__(self, other: Series[Timedelta]) -> PeriodSeries: ...
8685
@overload
8786
def __sub__(self, other: TimedeltaIndex) -> PeriodIndex: ...
8887
@overload
@@ -92,7 +91,7 @@ class Period(PeriodMixin):
9291
@overload
9392
def __add__(self, other: Index) -> PeriodIndex: ...
9493
@overload
95-
def __add__(self, other: OffsetSeries | TimedeltaSeries) -> PeriodSeries: ...
94+
def __add__(self, other: OffsetSeries | Series[Timedelta]) -> PeriodSeries: ...
9695
# ignore[misc] here because we know all other comparisons
9796
# are False, so we use Literal[False]
9897
@overload
@@ -148,7 +147,7 @@ class Period(PeriodMixin):
148147
@overload
149148
def __radd__(self, other: Index) -> Index: ...
150149
@overload
151-
def __radd__(self, other: TimedeltaSeries) -> PeriodSeries: ...
150+
def __radd__(self, other: Series[Timedelta]) -> PeriodSeries: ...
152151
@overload
153152
def __radd__(self, other: NaTType) -> NaTType: ...
154153
@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,
@@ -159,10 +158,7 @@ class Timedelta(timedelta):
159158
@overload
160159
def __add__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
161160
@overload
162-
def __add__(
163-
self,
164-
other: TimedeltaSeries,
165-
) -> TimedeltaSeries: ...
161+
def __add__(self, other: Series[Timedelta]) -> Series[Timedelta]: ...
166162
@overload
167163
def __add__(self, other: Series[Timestamp]) -> Series[Timestamp]: ...
168164
@overload
@@ -195,9 +191,7 @@ class Timedelta(timedelta):
195191
@overload
196192
def __sub__(self, other: pd.TimedeltaIndex) -> TimedeltaIndex: ...
197193
@overload
198-
def __sub__(
199-
self, other: TimedeltaSeries | Series[pd.Timedelta]
200-
) -> TimedeltaSeries: ...
194+
def __sub__(self, other: Series[pd.Timedelta]) -> Series[pd.Timedelta]: ...
201195
@overload
202196
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
203197
@overload
@@ -231,9 +225,9 @@ class Timedelta(timedelta):
231225
self, other: npt.NDArray[np.integer] | npt.NDArray[np.floating]
232226
) -> npt.NDArray[np.timedelta64]: ...
233227
@overload
234-
def __mul__(self, other: Series[int]) -> TimedeltaSeries: ...
228+
def __mul__(self, other: Series[int]) -> Series[Timedelta]: ...
235229
@overload
236-
def __mul__(self, other: Series[float]) -> TimedeltaSeries: ...
230+
def __mul__(self, other: Series[float]) -> Series[Timedelta]: ...
237231
@overload
238232
def __mul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
239233
@overload
@@ -243,9 +237,9 @@ class Timedelta(timedelta):
243237
self, other: npt.NDArray[np.floating] | npt.NDArray[np.integer]
244238
) -> npt.NDArray[np.timedelta64]: ...
245239
@overload
246-
def __rmul__(self, other: Series[int]) -> TimedeltaSeries: ...
240+
def __rmul__(self, other: Series[int]) -> Series[Timedelta]: ...
247241
@overload
248-
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
242+
def __rmul__(self, other: Series[float]) -> Series[Timedelta]: ...
249243
# maybe related to https://github.com/python/mypy/issues/10755
250244
@overload
251245
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
@@ -266,11 +260,11 @@ class Timedelta(timedelta):
266260
@overload
267261
def __floordiv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
268262
@overload
269-
def __floordiv__(self, other: Series[int]) -> TimedeltaSeries: ...
263+
def __floordiv__(self, other: Series[int]) -> Series[Timedelta]: ...
270264
@overload
271-
def __floordiv__(self, other: Series[float]) -> TimedeltaSeries: ...
265+
def __floordiv__(self, other: Series[float]) -> Series[Timedelta]: ...
272266
@overload
273-
def __floordiv__(self, other: TimedeltaSeries) -> Series[int]: ...
267+
def __floordiv__(self, other: Series[Timedelta]) -> Series[int]: ...
274268
@overload
275269
def __floordiv__(self, other: NaTType | None) -> float: ...
276270
@overload
@@ -291,19 +285,19 @@ class Timedelta(timedelta):
291285
self, other: npt.NDArray[np.integer] | npt.NDArray[np.floating]
292286
) -> npt.NDArray[np.timedelta64]: ...
293287
@overload
294-
def __truediv__(self, other: TimedeltaSeries) -> Series[float]: ...
288+
def __truediv__(self, other: Series[Timedelta]) -> Series[float]: ...
295289
@overload
296-
def __truediv__(self, other: Series[int]) -> TimedeltaSeries: ...
290+
def __truediv__(self, other: Series[int]) -> Series[Timedelta]: ...
297291
@overload
298-
def __truediv__(self, other: Series[float]) -> TimedeltaSeries: ...
292+
def __truediv__(self, other: Series[float]) -> Series[Timedelta]: ...
299293
@overload
300294
def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
301295
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
302296
# Override due to more types supported than dt.timedelta
303297
@overload
304298
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
305299
@overload
306-
def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
300+
def __eq__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
307301
@overload
308302
def __eq__( # type: ignore[overload-overlap]
309303
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
@@ -314,7 +308,7 @@ class Timedelta(timedelta):
314308
@overload
315309
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
316310
@overload
317-
def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
311+
def __ne__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
318312
@overload
319313
def __ne__( # type: ignore[overload-overlap]
320314
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
@@ -327,7 +321,7 @@ class Timedelta(timedelta):
327321
@overload
328322
def __mod__(self, other: float) -> Timedelta: ...
329323
@overload
330-
def __mod__(self, other: Series[int] | Series[float]) -> TimedeltaSeries: ...
324+
def __mod__(self, other: Series[int] | Series[float]) -> Series[Timedelta]: ...
331325
@overload
332326
def __mod__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
333327
@overload
@@ -336,8 +330,8 @@ class Timedelta(timedelta):
336330
) -> npt.NDArray[np.timedelta64]: ...
337331
@overload
338332
def __mod__(
339-
self, other: Series[int] | Series[float] | TimedeltaSeries
340-
) -> TimedeltaSeries: ...
333+
self, other: Series[int] | Series[float] | Series[Timedelta]
334+
) -> Series[Timedelta]: ...
341335
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
342336
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
343337
# for le, lt ge and gt
@@ -349,7 +343,7 @@ class Timedelta(timedelta):
349343
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
350344
) -> npt.NDArray[np.bool_]: ...
351345
@overload
352-
def __le__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
346+
def __le__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
353347
# Override due to more types supported than dt.timedelta
354348
@overload # type: ignore[override]
355349
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@@ -358,7 +352,7 @@ class Timedelta(timedelta):
358352
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
359353
) -> npt.NDArray[np.bool_]: ...
360354
@overload
361-
def __lt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
355+
def __lt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
362356
# Override due to more types supported than dt.timedelta
363357
@overload # type: ignore[override]
364358
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@@ -367,7 +361,7 @@ class Timedelta(timedelta):
367361
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
368362
) -> npt.NDArray[np.bool_]: ...
369363
@overload
370-
def __ge__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
364+
def __ge__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
371365
# Override due to more types supported than dt.timedelta
372366
@overload # type: ignore[override]
373367
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@@ -376,7 +370,7 @@ class Timedelta(timedelta):
376370
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
377371
) -> npt.NDArray[np.bool_]: ...
378372
@overload
379-
def __gt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
373+
def __gt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
380374
def __hash__(self) -> int: ...
381375
def isoformat(self) -> str: ...
382376
def to_numpy(self) -> np.timedelta64: ...

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ from pandas import (
2222
Index,
2323
TimedeltaIndex,
2424
)
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,
@@ -204,7 +201,7 @@ class Timestamp(datetime, SupportsIndex):
204201
@overload
205202
def __add__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
206203
@overload
207-
def __add__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
204+
def __add__(self, other: Series[Timedelta]) -> Series[Timestamp]: ...
208205
@overload
209206
def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
210207
@overload
@@ -223,9 +220,9 @@ class Timestamp(datetime, SupportsIndex):
223220
@overload
224221
def __sub__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
225222
@overload
226-
def __sub__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
223+
def __sub__(self, other: Series[Timedelta]) -> Series[Timestamp]: ...
227224
@overload
228-
def __sub__(self, other: Series[Timestamp]) -> TimedeltaSeries: ...
225+
def __sub__(self, other: Series[Timestamp]) -> Series[Timedelta]: ...
229226
@overload
230227
def __sub__(
231228
self, other: npt.NDArray[np.timedelta64]

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ from pandas.core.frame import DataFrame
3131
from pandas.core.series import (
3232
PeriodSeries,
3333
Series,
34-
TimedeltaSeries,
3534
)
3635
from typing_extensions import Never
3736

@@ -316,11 +315,11 @@ class _TimedeltaPropertiesNoRounding(
316315
class TimedeltaProperties(
317316
Properties,
318317
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
319-
_DatetimeRoundingMethods[TimedeltaSeries],
318+
_DatetimeRoundingMethods[Series[Timedelta]],
320319
):
321320
@property
322321
def unit(self) -> TimeUnit: ...
323-
def as_unit(self, unit: TimeUnit) -> TimedeltaSeries: ...
322+
def as_unit(self, unit: TimeUnit) -> Series[Timedelta]: ...
324323

325324
_PeriodDTReturnTypes = TypeVar(
326325
"_PeriodDTReturnTypes", bound=Series[Timestamp] | DatetimeIndex
@@ -439,6 +438,10 @@ class _dtDescriptor(CombinedDatetimelikeProperties, Generic[S1]):
439438
self, instance: Series[Timestamp], owner: Any
440439
) -> TimestampProperties: ...
441440
@overload
441+
def __get__(
442+
self, instance: Series[Timedelta], owner: Any
443+
) -> TimedeltaProperties: ...
444+
@overload
442445
def __get__(
443446
self, instance: Series[S1], owner: Any
444447
) -> CombinedDatetimelikeProperties: ...

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ from pandas import (
1919
)
2020
from pandas.core.indexes.accessors import DatetimeIndexProperties
2121
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
22-
from pandas.core.series import (
23-
Series,
24-
TimedeltaSeries,
25-
)
22+
from pandas.core.series import Series
2623
from typing_extensions import Self
2724

2825
from pandas._typing import (
@@ -57,13 +54,13 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
5754
# various ignores needed for mypy, as we do want to restrict what can be used in
5855
# arithmetic for these types
5956
@overload
60-
def __add__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
57+
def __add__(self, other: Series[Timedelta]) -> Series[Timestamp]: ...
6158
@overload
6259
def __add__(
6360
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset
6461
) -> DatetimeIndex: ...
6562
@overload
66-
def __sub__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
63+
def __sub__(self, other: Series[Timedelta]) -> Series[Timestamp]: ...
6764
@overload
6865
def __sub__(
6966
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset

pandas-stubs/core/indexes/interval.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import numpy as np
1212
import pandas as pd
1313
from pandas import Index
1414
from pandas.core.indexes.extension import ExtensionIndex
15-
from pandas.core.series import (
16-
TimedeltaSeries,
17-
)
1815
from typing_extensions import TypeAlias
1916

2017
from pandas._libs.interval import (
@@ -57,7 +54,7 @@ _EdgesTimestamp: TypeAlias = (
5754
_EdgesTimedelta: TypeAlias = (
5855
Sequence[pd.Timedelta]
5956
| npt.NDArray[np.timedelta64]
60-
| TimedeltaSeries
57+
| pd.Series[pd.Timedelta]
6158
| pd.TimedeltaIndex
6259
)
6360
_TimestampLike: TypeAlias = pd.Timestamp | np.datetime64 | dt.datetime

pandas-stubs/core/indexes/timedeltas.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from pandas.core.indexes.accessors import TimedeltaIndexProperties
1818
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
1919
from pandas.core.indexes.datetimes import DatetimeIndex
2020
from pandas.core.indexes.period import PeriodIndex
21-
from pandas.core.series import TimedeltaSeries
21+
from pandas.core.series import Series
2222
from typing_extensions import Self
2323

2424
from pandas._libs import (
@@ -73,7 +73,7 @@ class TimedeltaIndex(DatetimeTimedeltaMixin[Timedelta], TimedeltaIndexProperties
7373
def searchsorted(self, value, side: str = ..., sorter=...): ...
7474
@property
7575
def inferred_type(self) -> str: ...
76-
def to_series(self, index=..., name: Hashable = ...) -> TimedeltaSeries: ...
76+
def to_series(self, index=..., name: Hashable = ...) -> Series[Timedelta]: ...
7777
def shift(self, periods: int = ..., freq=...) -> Self: ...
7878

7979
def timedelta_range(

0 commit comments

Comments
 (0)