@@ -9,8 +9,6 @@ from time import struct_time
99from typing import (
1010 ClassVar ,
1111 Literal ,
12- TypeVar ,
13- Union ,
1412 overload ,
1513)
1614
@@ -25,7 +23,10 @@ from pandas.core.series import (
2523 TimedeltaSeries ,
2624 TimestampSeries ,
2725)
28- from typing_extensions import TypeAlias
26+ from typing_extensions import (
27+ Self ,
28+ TypeAlias ,
29+ )
2930
3031from pandas ._libs .tslibs import (
3132 BaseOffset ,
@@ -38,11 +39,10 @@ from pandas._typing import (
3839 npt ,
3940)
4041
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+ )
4646
4747class Timestamp (datetime ):
4848 min : ClassVar [Timestamp ]
@@ -51,7 +51,7 @@ class Timestamp(datetime):
5151 resolution : ClassVar [Timedelta ]
5252 value : int
5353 def __new__ (
54- cls : type [ _DatetimeT ] ,
54+ cls ,
5555 ts_input : np .integer | float | str | _date | datetime | np .datetime64 = ...,
5656 # Freq is deprecated but is left in to allow code like Timestamp(2000,1,1)
5757 # Removing it would make the other arguments position only
@@ -69,7 +69,7 @@ class Timestamp(datetime):
6969 tzinfo : _tzinfo | None = ...,
7070 * ,
7171 fold : Literal [0 , 1 ] | None = ...,
72- ) -> _DatetimeT : ...
72+ ) -> Self : ...
7373 # GH 46171
7474 # While Timestamp can return pd.NaT, having the constructor return
7575 # a Union with NaTType makes things awkward for users of pandas
@@ -96,30 +96,28 @@ class Timestamp(datetime):
9696 @property
9797 def fold (self ) -> int : ...
9898 @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 : ...
102100 @classmethod
103- def utcfromtimestamp (cls : type [ _DatetimeT ] , ts : float ) -> _DatetimeT : ...
101+ def utcfromtimestamp (cls , ts : float ) -> Self : ...
104102 @classmethod
105- def today (cls : type [ _DatetimeT ] , tz : _tzinfo | str | None = ...) -> _DatetimeT : ...
103+ def today (cls , tz : _tzinfo | str | None = ...) -> Self : ...
106104 @classmethod
107105 def fromordinal (
108- cls : type [ _DatetimeT ] ,
106+ cls ,
109107 ordinal : int ,
110108 # freq produces a FutureWarning about being deprecated in a future version
111109 freq : None = ...,
112110 tz : _tzinfo | str | None = ...,
113- ) -> _DatetimeT : ...
111+ ) -> Self : ...
114112 @classmethod
115- def now (cls : type [ _DatetimeT ] , tz : _tzinfo | str | None = ...) -> _DatetimeT : ...
113+ def now (cls , tz : _tzinfo | str | None = ...) -> Self : ...
116114 @classmethod
117- def utcnow (cls : type [ _DatetimeT ] ) -> _DatetimeT : ...
115+ def utcnow (cls ) -> Self : ...
118116 # error: Signature of "combine" incompatible with supertype "datetime"
119117 @classmethod
120118 def combine (cls , date : _date , time : _time ) -> datetime : ... # type: ignore[override]
121119 @classmethod
122- def fromisoformat (cls : type [ _DatetimeT ] , date_string : str ) -> _DatetimeT : ...
120+ def fromisoformat (cls , date_string : str ) -> Self : ...
123121 def strftime (self , format : str ) -> str : ...
124122 def __format__ (self , fmt : str ) -> str : ...
125123 def toordinal (self ) -> int : ...
@@ -144,7 +142,7 @@ class Timestamp(datetime):
144142 tzinfo : _tzinfo | None = ...,
145143 fold : Literal [0 , 1 ] | None = ...,
146144 ) -> Timestamp : ...
147- def astimezone (self : _DatetimeT , tz : _tzinfo | None = ...) -> _DatetimeT : ...
145+ def astimezone (self , tz : _tzinfo | None = ...) -> Self : ...
148146 def ctime (self ) -> str : ...
149147 def isoformat (self , sep : str = ..., timespec : str = ...) -> str : ...
150148 @classmethod
@@ -184,15 +182,13 @@ class Timestamp(datetime):
184182 self , other : npt .NDArray [np .timedelta64 ]
185183 ) -> npt .NDArray [np .datetime64 ]: ...
186184 @overload
187- def __add__ (
188- self : _DatetimeT , other : timedelta | np .timedelta64 | Tick
189- ) -> _DatetimeT : ...
185+ def __add__ (self , other : timedelta | np .timedelta64 | Tick ) -> Self : ...
190186 @overload
191187 def __add__ (self , other : TimedeltaSeries ) -> TimestampSeries : ...
192188 @overload
193189 def __add__ (self , other : TimedeltaIndex ) -> DatetimeIndex : ...
194190 @overload
195- def __radd__ (self : _DatetimeT , other : timedelta ) -> _DatetimeT : ...
191+ def __radd__ (self , other : timedelta ) -> Self : ...
196192 @overload
197193 def __radd__ (self , other : TimedeltaIndex ) -> DatetimeIndex : ...
198194 @overload
@@ -203,9 +199,7 @@ class Timestamp(datetime):
203199 @overload # type: ignore[override]
204200 def __sub__ (self , other : Timestamp | datetime | np .datetime64 ) -> Timedelta : ...
205201 @overload
206- def __sub__ (
207- self : _DatetimeT , other : timedelta | np .timedelta64 | Tick
208- ) -> _DatetimeT : ...
202+ def __sub__ (self , other : timedelta | np .timedelta64 | Tick ) -> Self : ...
209203 @overload
210204 def __sub__ (self , other : TimedeltaIndex ) -> DatetimeIndex : ...
211205 @overload
@@ -253,34 +247,34 @@ class Timestamp(datetime):
253247 def to_julian_date (self ) -> np .float64 : ...
254248 @property
255249 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 : ...
257251 # TODO: could return NaT?
258252 def tz_localize (
259- self : _DatetimeT ,
253+ self ,
260254 tz : _tzinfo | str | None ,
261255 ambiguous : _Ambiguous = ...,
262256 nonexistent : _Nonexistent = ...,
263- ) -> _DatetimeT : ...
264- def normalize (self : _DatetimeT ) -> _DatetimeT : ...
257+ ) -> Self : ...
258+ def normalize (self ) -> Self : ...
265259 # TODO: round/floor/ceil could return NaT?
266260 def round (
267- self : _DatetimeT ,
261+ self ,
268262 freq : str ,
269263 ambiguous : _Ambiguous = ...,
270264 nonexistent : _Nonexistent = ...,
271- ) -> _DatetimeT : ...
265+ ) -> Self : ...
272266 def floor (
273- self : _DatetimeT ,
267+ self ,
274268 freq : str ,
275269 ambiguous : _Ambiguous = ...,
276270 nonexistent : _Nonexistent = ...,
277- ) -> _DatetimeT : ...
271+ ) -> Self : ...
278272 def ceil (
279- self : _DatetimeT ,
273+ self ,
280274 freq : str ,
281275 ambiguous : _Ambiguous = ...,
282276 nonexistent : _Nonexistent = ...,
283- ) -> _DatetimeT : ...
277+ ) -> Self : ...
284278 def day_name (self , locale : str | None = ...) -> str : ...
285279 def month_name (self , locale : str | None = ...) -> str : ...
286280 @property
0 commit comments