Skip to content

Commit a096bc0

Browse files
committed
fix: #718 also remove TimedeltaSeries
1 parent 1410f27 commit a096bc0

File tree

15 files changed

+965
-457
lines changed

15 files changed

+965
-457
lines changed

docs/philosophy.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,6 @@ the type of `lt` is `Series[bool]`. This allows further type checking to occur
3232
pandas methods. Note that in the above example, `s` is just typed as `Series` (which
3333
defaults to `Series[Any]`) because its type cannot be statically inferred.
3434

35-
This also allows type checking for operations on series that contain date/time data. Consider
36-
the following example that creates two series of datetimes with corresponding arithmetic.
37-
38-
```python
39-
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"]))
40-
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"]))
41-
td = s1 - s2
42-
reveal_type(td)
43-
ssum = s1 + s2
44-
reveal_type(ssum)
45-
```
46-
47-
The above code (without the `reveal_type()` statements) will raise an `Exception` on the computation of `ssum` because it is
48-
inappropriate to add two series containing `Timestamp` values. The types will be
49-
revealed as follows:
50-
51-
```text
52-
ttest.py:3: note: Revealed type is "pandas.core.series.TimedeltaSeries"
53-
ttest.py:5: note: Revealed type is "builtins.Exception"
54-
```
55-
56-
The type `TimedeltaSeries` is the result of `pd.to_timedelta()`.
57-
5835
### Interval is Generic
5936

6037
A pandas `Interval` can be a time interval, an interval of integers, or an interval of

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[pd.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: 7 additions & 4 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

3736
from pandas._libs.tslibs import BaseOffset
@@ -164,7 +163,7 @@ class _DatetimeLikeOps(
164163

165164
_DTTimestampTimedeltaReturnType = TypeVar(
166165
"_DTTimestampTimedeltaReturnType",
167-
bound=Series | Series[Timestamp] | TimedeltaSeries | DatetimeIndex | TimedeltaIndex,
166+
bound=Series | Series[Timestamp] | DatetimeIndex | TimedeltaIndex,
168167
)
169168

170169
class _DatetimeRoundingMethods(Generic[_DTTimestampTimedeltaReturnType]):
@@ -315,11 +314,11 @@ class _TimedeltaPropertiesNoRounding(
315314
class TimedeltaProperties(
316315
Properties,
317316
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
318-
_DatetimeRoundingMethods[TimedeltaSeries],
317+
_DatetimeRoundingMethods[Series[Timedelta]],
319318
):
320319
@property
321320
def unit(self) -> TimeUnit: ...
322-
def as_unit(self, unit: TimeUnit) -> TimedeltaSeries: ...
321+
def as_unit(self, unit: TimeUnit) -> Series[Timedelta]: ...
323322

324323
_PeriodDTReturnTypes = TypeVar(
325324
"_PeriodDTReturnTypes", bound=Series[Timestamp] | DatetimeIndex
@@ -436,6 +435,10 @@ class _dtDescriptor:
436435
self, instance: Series[Timestamp], owner: Any
437436
) -> TimestampProperties: ...
438437
@overload
438+
def __get__(
439+
self, instance: Series[Timedelta], owner: Any
440+
) -> TimedeltaProperties: ...
441+
@overload
439442
def __get__(
440443
self, instance: Series, owner: Any
441444
) -> 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: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ from typing import (
1010

1111
import numpy as np
1212
import pandas as pd
13-
from pandas import (
14-
Index,
15-
Timestamp,
16-
)
13+
from pandas import Index
1714
from pandas.core.indexes.extension import ExtensionIndex
18-
from pandas.core.series import (
19-
Series,
20-
TimedeltaSeries,
21-
)
2215
from typing_extensions import TypeAlias
2316

2417
from pandas._libs.interval import (
@@ -55,13 +48,13 @@ _EdgesFloat: TypeAlias = (
5548
_EdgesTimestamp: TypeAlias = (
5649
Sequence[DatetimeLike]
5750
| npt.NDArray[np.datetime64]
58-
| Series[Timestamp]
51+
| pd.Series[pd.Timestamp]
5952
| pd.DatetimeIndex
6053
)
6154
_EdgesTimedelta: TypeAlias = (
6255
Sequence[pd.Timedelta]
6356
| npt.NDArray[np.timedelta64]
64-
| TimedeltaSeries
57+
| pd.Series[pd.Timedelta]
6558
| pd.TimedeltaIndex
6659
)
6760
_TimestampLike: TypeAlias = pd.Timestamp | np.datetime64 | dt.datetime

0 commit comments

Comments
 (0)