@@ -9,8 +9,6 @@ from time import struct_time
9
9
from typing import (
10
10
ClassVar ,
11
11
Literal ,
12
- TypeVar ,
13
- Union ,
14
12
overload ,
15
13
)
16
14
@@ -25,7 +23,10 @@ from pandas.core.series import (
25
23
TimedeltaSeries ,
26
24
TimestampSeries ,
27
25
)
28
- from typing_extensions import TypeAlias
26
+ from typing_extensions import (
27
+ Self ,
28
+ TypeAlias ,
29
+ )
29
30
30
31
from pandas ._libs .tslibs import (
31
32
BaseOffset ,
@@ -38,11 +39,10 @@ from pandas._typing import (
38
39
npt ,
39
40
)
40
41
41
- _DatetimeT = TypeVar ("_DatetimeT" , bound = datetime )
42
- _Ambiguous : TypeAlias = Union [bool , Literal ["raise" , "NaT" ]]
43
- _Nonexistent : TypeAlias = Union [
44
- Literal ["raise" , "NaT" , "shift_backward" , "shift_forward" ], Timedelta , timedelta
45
- ]
42
+ _Ambiguous : TypeAlias = bool | Literal ["raise" , "NaT" ]
43
+ _Nonexistent : TypeAlias = (
44
+ Literal ["raise" , "NaT" , "shift_backward" , "shift_forward" ] | Timedelta | timedelta
45
+ )
46
46
47
47
class Timestamp (datetime ):
48
48
min : ClassVar [Timestamp ]
@@ -51,7 +51,7 @@ class Timestamp(datetime):
51
51
resolution : ClassVar [Timedelta ]
52
52
value : int
53
53
def __new__ (
54
- cls : type [ _DatetimeT ] ,
54
+ cls ,
55
55
ts_input : np .integer | float | str | _date | datetime | np .datetime64 = ...,
56
56
# Freq is deprecated but is left in to allow code like Timestamp(2000,1,1)
57
57
# Removing it would make the other arguments position only
@@ -69,7 +69,7 @@ class Timestamp(datetime):
69
69
tzinfo : _tzinfo | None = ...,
70
70
* ,
71
71
fold : Literal [0 , 1 ] | None = ...,
72
- ) -> _DatetimeT : ...
72
+ ) -> Self : ...
73
73
# GH 46171
74
74
# While Timestamp can return pd.NaT, having the constructor return
75
75
# a Union with NaTType makes things awkward for users of pandas
@@ -96,30 +96,28 @@ class Timestamp(datetime):
96
96
@property
97
97
def fold (self ) -> int : ...
98
98
@classmethod
99
- def fromtimestamp (
100
- cls : type [_DatetimeT ], t : float , tz : _tzinfo | str | None = ...
101
- ) -> _DatetimeT : ...
99
+ def fromtimestamp (cls , t : float , tz : _tzinfo | str | None = ...) -> Self : ...
102
100
@classmethod
103
- def utcfromtimestamp (cls : type [ _DatetimeT ] , ts : float ) -> _DatetimeT : ...
101
+ def utcfromtimestamp (cls , ts : float ) -> Self : ...
104
102
@classmethod
105
- def today (cls : type [ _DatetimeT ] , tz : _tzinfo | str | None = ...) -> _DatetimeT : ...
103
+ def today (cls , tz : _tzinfo | str | None = ...) -> Self : ...
106
104
@classmethod
107
105
def fromordinal (
108
- cls : type [ _DatetimeT ] ,
106
+ cls ,
109
107
ordinal : int ,
110
108
# freq produces a FutureWarning about being deprecated in a future version
111
109
freq : None = ...,
112
110
tz : _tzinfo | str | None = ...,
113
- ) -> _DatetimeT : ...
111
+ ) -> Self : ...
114
112
@classmethod
115
- def now (cls : type [ _DatetimeT ] , tz : _tzinfo | str | None = ...) -> _DatetimeT : ...
113
+ def now (cls , tz : _tzinfo | str | None = ...) -> Self : ...
116
114
@classmethod
117
- def utcnow (cls : type [ _DatetimeT ] ) -> _DatetimeT : ...
115
+ def utcnow (cls ) -> Self : ...
118
116
# error: Signature of "combine" incompatible with supertype "datetime"
119
117
@classmethod
120
118
def combine (cls , date : _date , time : _time ) -> datetime : ... # type: ignore[override]
121
119
@classmethod
122
- def fromisoformat (cls : type [ _DatetimeT ] , date_string : str ) -> _DatetimeT : ...
120
+ def fromisoformat (cls , date_string : str ) -> Self : ...
123
121
def strftime (self , format : str ) -> str : ...
124
122
def __format__ (self , fmt : str ) -> str : ...
125
123
def toordinal (self ) -> int : ...
@@ -144,7 +142,7 @@ class Timestamp(datetime):
144
142
tzinfo : _tzinfo | None = ...,
145
143
fold : Literal [0 , 1 ] | None = ...,
146
144
) -> Timestamp : ...
147
- def astimezone (self : _DatetimeT , tz : _tzinfo | None = ...) -> _DatetimeT : ...
145
+ def astimezone (self , tz : _tzinfo | None = ...) -> Self : ...
148
146
def ctime (self ) -> str : ...
149
147
def isoformat (self , sep : str = ..., timespec : str = ...) -> str : ...
150
148
@classmethod
@@ -184,15 +182,13 @@ class Timestamp(datetime):
184
182
self , other : npt .NDArray [np .timedelta64 ]
185
183
) -> npt .NDArray [np .datetime64 ]: ...
186
184
@overload
187
- def __add__ (
188
- self : _DatetimeT , other : timedelta | np .timedelta64 | Tick
189
- ) -> _DatetimeT : ...
185
+ def __add__ (self , other : timedelta | np .timedelta64 | Tick ) -> Self : ...
190
186
@overload
191
187
def __add__ (self , other : TimedeltaSeries ) -> TimestampSeries : ...
192
188
@overload
193
189
def __add__ (self , other : TimedeltaIndex ) -> DatetimeIndex : ...
194
190
@overload
195
- def __radd__ (self : _DatetimeT , other : timedelta ) -> _DatetimeT : ...
191
+ def __radd__ (self , other : timedelta ) -> Self : ...
196
192
@overload
197
193
def __radd__ (self , other : TimedeltaIndex ) -> DatetimeIndex : ...
198
194
@overload
@@ -203,9 +199,7 @@ class Timestamp(datetime):
203
199
@overload # type: ignore[override]
204
200
def __sub__ (self , other : Timestamp | datetime | np .datetime64 ) -> Timedelta : ...
205
201
@overload
206
- def __sub__ (
207
- self : _DatetimeT , other : timedelta | np .timedelta64 | Tick
208
- ) -> _DatetimeT : ...
202
+ def __sub__ (self , other : timedelta | np .timedelta64 | Tick ) -> Self : ...
209
203
@overload
210
204
def __sub__ (self , other : TimedeltaIndex ) -> DatetimeIndex : ...
211
205
@overload
@@ -253,34 +247,34 @@ class Timestamp(datetime):
253
247
def to_julian_date (self ) -> np .float64 : ...
254
248
@property
255
249
def asm8 (self ) -> np .datetime64 : ...
256
- def tz_convert (self : _DatetimeT , tz : _tzinfo | str | None ) -> _DatetimeT : ...
250
+ def tz_convert (self , tz : _tzinfo | str | None ) -> Self : ...
257
251
# TODO: could return NaT?
258
252
def tz_localize (
259
- self : _DatetimeT ,
253
+ self ,
260
254
tz : _tzinfo | str | None ,
261
255
ambiguous : _Ambiguous = ...,
262
256
nonexistent : _Nonexistent = ...,
263
- ) -> _DatetimeT : ...
264
- def normalize (self : _DatetimeT ) -> _DatetimeT : ...
257
+ ) -> Self : ...
258
+ def normalize (self ) -> Self : ...
265
259
# TODO: round/floor/ceil could return NaT?
266
260
def round (
267
- self : _DatetimeT ,
261
+ self ,
268
262
freq : str ,
269
263
ambiguous : _Ambiguous = ...,
270
264
nonexistent : _Nonexistent = ...,
271
- ) -> _DatetimeT : ...
265
+ ) -> Self : ...
272
266
def floor (
273
- self : _DatetimeT ,
267
+ self ,
274
268
freq : str ,
275
269
ambiguous : _Ambiguous = ...,
276
270
nonexistent : _Nonexistent = ...,
277
- ) -> _DatetimeT : ...
271
+ ) -> Self : ...
278
272
def ceil (
279
- self : _DatetimeT ,
273
+ self ,
280
274
freq : str ,
281
275
ambiguous : _Ambiguous = ...,
282
276
nonexistent : _Nonexistent = ...,
283
- ) -> _DatetimeT : ...
277
+ ) -> Self : ...
284
278
def day_name (self , locale : str | None = ...) -> str : ...
285
279
def month_name (self , locale : str | None = ...) -> str : ...
286
280
@property
0 commit comments