Skip to content

Commit 1410f27

Browse files
committed
fix: #718 attempt to drop TimestampSeries
1 parent f6dd4a2 commit 1410f27

File tree

15 files changed

+337
-269
lines changed

15 files changed

+337
-269
lines changed

docs/philosophy.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ the following example that creates two series of datetimes with corresponding ar
3737

3838
```python
3939
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"]))
40-
reveal_type(s1)
4140
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"]))
42-
reveal_type(s2)
4341
td = s1 - s2
4442
reveal_type(td)
4543
ssum = s1 + s2
@@ -51,15 +49,11 @@ inappropriate to add two series containing `Timestamp` values. The types will b
5149
revealed as follows:
5250

5351
```text
54-
ttest.py:4: note: Revealed type is "pandas.core.series.TimestampSeries"
55-
ttest.py:6: note: Revealed type is "pandas.core.series.TimestampSeries"
56-
ttest.py:8: note: Revealed type is "pandas.core.series.TimedeltaSeries"
57-
ttest.py:10: note: Revealed type is "builtins.Exception"
52+
ttest.py:3: note: Revealed type is "pandas.core.series.TimedeltaSeries"
53+
ttest.py:5: note: Revealed type is "builtins.Exception"
5854
```
5955

60-
The type `TimestampSeries` is the result of creating a series from `pd.to_datetime()`, while
61-
the type `TimedeltaSeries` is the result of subtracting two `TimestampSeries` as well as
62-
the result of `pd.to_timedelta()`.
56+
The type `TimedeltaSeries` is the result of `pd.to_timedelta()`.
6357

6458
### Interval is Generic
6559

pandas-stubs/_libs/interval.pyi

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ from pandas import (
1313
Timedelta,
1414
Timestamp,
1515
)
16-
from pandas.core.series import (
17-
TimedeltaSeries,
18-
TimestampSeries,
19-
)
16+
from pandas.core.series import TimedeltaSeries
2017

2118
from pandas._typing import (
2219
IntervalClosedType,
@@ -174,7 +171,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
174171
@overload
175172
def __gt__(
176173
self,
177-
other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries,
174+
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
178175
) -> Series[bool]: ...
179176
@overload
180177
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
@@ -183,7 +180,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
183180
@overload
184181
def __lt__(
185182
self,
186-
other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries,
183+
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
187184
) -> Series[bool]: ...
188185
@overload
189186
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
@@ -192,7 +189,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
192189
@overload
193190
def __ge__(
194191
self,
195-
other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries,
192+
other: Series[int] | Series[float] | Series[Timestamp] | TimedeltaSeries,
196193
) -> Series[bool]: ...
197194
@overload
198195
def __le__(self, other: Interval[_OrderableT]) -> bool: ...

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ from pandas import (
1717
Series,
1818
TimedeltaIndex,
1919
)
20-
from pandas.core.series import (
21-
TimedeltaSeries,
22-
TimestampSeries,
23-
)
20+
from pandas.core.series import TimedeltaSeries
2421
from typing_extensions import (
2522
Self,
2623
TypeAlias,
@@ -167,7 +164,7 @@ class Timedelta(timedelta):
167164
other: TimedeltaSeries,
168165
) -> TimedeltaSeries: ...
169166
@overload
170-
def __add__(self, other: TimestampSeries) -> TimestampSeries: ...
167+
def __add__(self, other: Series[Timestamp]) -> Series[Timestamp]: ...
171168
@overload
172169
def __radd__(self, other: np.datetime64) -> Timestamp: ...
173170
@overload

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ from pandas import (
2525
from pandas.core.series import (
2626
Series,
2727
TimedeltaSeries,
28-
TimestampSeries,
2928
)
3029
from typing_extensions import (
3130
Never,
@@ -172,31 +171,31 @@ class Timestamp(datetime, SupportsIndex):
172171
self, other: DatetimeIndex | npt.NDArray[np.datetime64]
173172
) -> np_ndarray_bool: ...
174173
@overload
175-
def __le__(self, other: TimestampSeries) -> Series[bool]: ...
174+
def __le__(self, other: Series[Timestamp]) -> Series[bool]: ...
176175
@overload # type: ignore[override]
177176
def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
178177
@overload
179178
def __lt__(
180179
self, other: DatetimeIndex | npt.NDArray[np.datetime64]
181180
) -> np_ndarray_bool: ...
182181
@overload
183-
def __lt__(self, other: TimestampSeries) -> Series[bool]: ...
182+
def __lt__(self, other: Series[Timestamp]) -> Series[bool]: ...
184183
@overload # type: ignore[override]
185184
def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
186185
@overload
187186
def __ge__(
188187
self, other: DatetimeIndex | npt.NDArray[np.datetime64]
189188
) -> np_ndarray_bool: ...
190189
@overload
191-
def __ge__(self, other: TimestampSeries) -> Series[bool]: ...
190+
def __ge__(self, other: Series[Timestamp]) -> Series[bool]: ...
192191
@overload # type: ignore[override]
193192
def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
194193
@overload
195194
def __gt__(
196195
self, other: DatetimeIndex | npt.NDArray[np.datetime64]
197196
) -> np_ndarray_bool: ...
198197
@overload
199-
def __gt__(self, other: TimestampSeries) -> Series[bool]: ...
198+
def __gt__(self, other: Series[Timestamp]) -> Series[bool]: ...
200199
# error: Signature of "__add__" incompatible with supertype "date"/"datetime"
201200
@overload # type: ignore[override]
202201
def __add__(
@@ -205,7 +204,7 @@ class Timestamp(datetime, SupportsIndex):
205204
@overload
206205
def __add__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
207206
@overload
208-
def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ...
207+
def __add__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
209208
@overload
210209
def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
211210
@overload
@@ -224,25 +223,25 @@ class Timestamp(datetime, SupportsIndex):
224223
@overload
225224
def __sub__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
226225
@overload
227-
def __sub__(self, other: TimedeltaSeries) -> TimestampSeries: ...
226+
def __sub__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
228227
@overload
229-
def __sub__(self, other: TimestampSeries) -> TimedeltaSeries: ...
228+
def __sub__(self, other: Series[Timestamp]) -> TimedeltaSeries: ...
230229
@overload
231230
def __sub__(
232231
self, other: npt.NDArray[np.timedelta64]
233232
) -> npt.NDArray[np.datetime64]: ...
234233
@overload
235234
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
236235
@overload
237-
def __eq__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
236+
def __eq__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
238237
@overload
239238
def __eq__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
240239
@overload
241240
def __eq__(self, other: object) -> Literal[False]: ...
242241
@overload
243242
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
244243
@overload
245-
def __ne__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
244+
def __ne__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
246245
@overload
247246
def __ne__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
248247
@overload

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ from datetime import (
44
tzinfo as _tzinfo,
55
)
66
from typing import (
7+
Any,
78
Generic,
89
Literal,
910
TypeVar,
11+
overload,
1012
)
1113

1214
import numpy as np
@@ -17,6 +19,7 @@ from pandas import (
1719
PeriodIndex,
1820
Timedelta,
1921
TimedeltaIndex,
22+
Timestamp,
2023
)
2124
from pandas.core.accessor import PandasDelegate
2225
from pandas.core.arrays import (
@@ -29,7 +32,6 @@ from pandas.core.series import (
2932
PeriodSeries,
3033
Series,
3134
TimedeltaSeries,
32-
TimestampSeries,
3335
)
3436

3537
from pandas._libs.tslibs import BaseOffset
@@ -162,7 +164,7 @@ class _DatetimeLikeOps(
162164

163165
_DTTimestampTimedeltaReturnType = TypeVar(
164166
"_DTTimestampTimedeltaReturnType",
165-
bound=Series | TimestampSeries | TimedeltaSeries | DatetimeIndex | TimedeltaIndex,
167+
bound=Series | Series[Timestamp] | TimedeltaSeries | DatetimeIndex | TimedeltaIndex,
166168
)
167169

168170
class _DatetimeRoundingMethods(Generic[_DTTimestampTimedeltaReturnType]):
@@ -198,7 +200,7 @@ class _DatetimeRoundingMethods(Generic[_DTTimestampTimedeltaReturnType]):
198200
) -> _DTTimestampTimedeltaReturnType: ...
199201

200202
_DTNormalizeReturnType = TypeVar(
201-
"_DTNormalizeReturnType", TimestampSeries, DatetimeIndex
203+
"_DTNormalizeReturnType", Series[Timestamp], DatetimeIndex
202204
)
203205
_DTStrKindReturnType = TypeVar("_DTStrKindReturnType", bound=Series[str] | Index)
204206
_DTToPeriodReturnType = TypeVar(
@@ -320,7 +322,7 @@ class TimedeltaProperties(
320322
def as_unit(self, unit: TimeUnit) -> TimedeltaSeries: ...
321323

322324
_PeriodDTReturnTypes = TypeVar(
323-
"_PeriodDTReturnTypes", bound=TimestampSeries | DatetimeIndex
325+
"_PeriodDTReturnTypes", bound=Series[Timestamp] | DatetimeIndex
324326
)
325327
_PeriodIntReturnTypes = TypeVar("_PeriodIntReturnTypes", bound=Series[int] | Index[int])
326328
_PeriodStrReturnTypes = TypeVar("_PeriodStrReturnTypes", bound=Series[str] | Index)
@@ -363,7 +365,7 @@ class PeriodIndexFieldOps(
363365
class PeriodProperties(
364366
Properties,
365367
_PeriodProperties[
366-
TimestampSeries, Series[int], Series[str], DatetimeArray, PeriodArray
368+
Series[Timestamp], Series[int], Series[str], DatetimeArray, PeriodArray
367369
],
368370
_DatetimeFieldOps[Series[int]],
369371
_IsLeapYearProperty,
@@ -377,7 +379,7 @@ class CombinedDatetimelikeProperties(
377379
Series[dt.date],
378380
Series[dt.time],
379381
str,
380-
TimestampSeries,
382+
Series[Timestamp],
381383
Series[str],
382384
PeriodSeries,
383385
],
@@ -388,11 +390,11 @@ class TimestampProperties(
388390
DatetimeProperties[
389391
Series[int],
390392
Series[bool],
391-
TimestampSeries,
393+
Series[Timestamp],
392394
Series[dt.date],
393395
Series[dt.time],
394396
str,
395-
TimestampSeries,
397+
Series[Timestamp],
396398
Series[str],
397399
PeriodSeries,
398400
]
@@ -427,3 +429,13 @@ class TimedeltaIndexProperties(
427429
_TimedeltaPropertiesNoRounding[Index, Index],
428430
_DatetimeRoundingMethods[TimedeltaIndex],
429431
): ...
432+
433+
class _dtDescriptor:
434+
@overload
435+
def __get__(
436+
self, instance: Series[Timestamp], owner: Any
437+
) -> TimestampProperties: ...
438+
@overload
439+
def __get__(
440+
self, instance: Series, owner: Any
441+
) -> CombinedDatetimelikeProperties: ...

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ from pandas import (
2020
from pandas.core.indexes.accessors import DatetimeIndexProperties
2121
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2222
from pandas.core.series import (
23+
Series,
2324
TimedeltaSeries,
24-
TimestampSeries,
2525
)
2626
from typing_extensions import Self
2727

@@ -57,13 +57,13 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
5757
# various ignores needed for mypy, as we do want to restrict what can be used in
5858
# arithmetic for these types
5959
@overload
60-
def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ...
60+
def __add__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
6161
@overload
6262
def __add__(
6363
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset
6464
) -> DatetimeIndex: ...
6565
@overload
66-
def __sub__(self, other: TimedeltaSeries) -> TimestampSeries: ...
66+
def __sub__(self, other: TimedeltaSeries) -> Series[Timestamp]: ...
6767
@overload
6868
def __sub__(
6969
self, other: timedelta | Timedelta | TimedeltaIndex | BaseOffset
@@ -72,7 +72,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
7272
def __sub__(
7373
self, other: datetime | Timestamp | DatetimeIndex
7474
) -> TimedeltaIndex: ...
75-
def to_series(self, index=..., name: Hashable = ...) -> TimestampSeries: ...
75+
def to_series(self, index=..., name: Hashable = ...) -> Series[Timestamp]: ...
7676
def snap(self, freq: str = ...): ...
7777
def slice_indexer(self, start=..., end=..., step=...): ...
7878
def searchsorted(self, value, side: str = ..., sorter=...): ...

pandas-stubs/core/indexes/interval.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ from typing import (
1010

1111
import numpy as np
1212
import pandas as pd
13-
from pandas import Index
13+
from pandas import (
14+
Index,
15+
Timestamp,
16+
)
1417
from pandas.core.indexes.extension import ExtensionIndex
1518
from pandas.core.series import (
19+
Series,
1620
TimedeltaSeries,
17-
TimestampSeries,
1821
)
1922
from typing_extensions import TypeAlias
2023

@@ -52,7 +55,7 @@ _EdgesFloat: TypeAlias = (
5255
_EdgesTimestamp: TypeAlias = (
5356
Sequence[DatetimeLike]
5457
| npt.NDArray[np.datetime64]
55-
| TimestampSeries
58+
| Series[Timestamp]
5659
| pd.DatetimeIndex
5760
)
5861
_EdgesTimedelta: TypeAlias = (

pandas-stubs/core/reshape/tile.pyi

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from pandas import (
1515
Series,
1616
Timestamp,
1717
)
18-
from pandas.core.series import TimestampSeries
1918

2019
from pandas._typing import (
2120
IntervalT,
@@ -51,10 +50,10 @@ def cut(
5150
) -> tuple[npt.NDArray[np.intp], IntervalIndex[IntervalT]]: ...
5251
@overload
5352
def cut( # pyright: ignore[reportOverlappingOverload]
54-
x: TimestampSeries,
53+
x: Series[Timestamp],
5554
bins: (
5655
int
57-
| TimestampSeries
56+
| Series[Timestamp]
5857
| DatetimeIndex
5958
| Sequence[Timestamp]
6059
| Sequence[np.datetime64]
@@ -70,7 +69,7 @@ def cut( # pyright: ignore[reportOverlappingOverload]
7069
) -> tuple[Series, DatetimeIndex]: ...
7170
@overload
7271
def cut(
73-
x: TimestampSeries,
72+
x: Series[Timestamp],
7473
bins: IntervalIndex[Interval[Timestamp]],
7574
right: bool = ...,
7675
labels: Sequence[Label] | None = ...,
@@ -156,10 +155,10 @@ def cut(
156155
) -> npt.NDArray[np.intp]: ...
157156
@overload
158157
def cut(
159-
x: TimestampSeries,
158+
x: Series[Timestamp],
160159
bins: (
161160
int
162-
| TimestampSeries
161+
| Series[Timestamp]
163162
| DatetimeIndex
164163
| Sequence[Timestamp]
165164
| Sequence[np.datetime64]

0 commit comments

Comments
 (0)