File tree Expand file tree Collapse file tree 5 files changed +16
-7
lines changed Expand file tree Collapse file tree 5 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ from pandas._libs.tslibs.period import Period
1717from pandas ._typing import (
1818 Frequency ,
1919 TimestampNonexistent ,
20+ TimeUnit ,
2021)
2122
2223NaT : NaTType
@@ -180,4 +181,4 @@ class NaTType:
180181 def __floordiv__ (self , other : float , / ) -> Self : ...
181182 # other
182183 def __hash__ (self ) -> int : ...
183- def as_unit (self , unit : str , round_ok : bool = ...) -> NaTType : ...
184+ def as_unit (self , unit : TimeUnit , round_ok : bool = ...) -> NaTType : ...
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ from pandas._libs.tslibs import (
1515)
1616from pandas ._typing import (
1717 Frequency ,
18+ TimeUnit ,
1819 npt ,
1920)
2021
@@ -162,5 +163,5 @@ class Timedelta(timedelta):
162163 ) -> np .timedelta64 : ...
163164 def view (self , dtype : npt .DTypeLike ) -> object : ...
164165 @property
165- def unit (self ) -> str : ...
166- def as_unit (self , unit : str , round_ok : bool = ...) -> Timedelta : ...
166+ def unit (self ) -> TimeUnit : ...
167+ def as_unit (self , unit : TimeUnit , round_ok : bool = ...) -> Timedelta : ...
Original file line number Diff line number Diff line change @@ -23,7 +23,10 @@ from pandas._libs.tslibs import (
2323 Tick ,
2424 Timedelta ,
2525)
26- from pandas ._typing import TimestampNonexistent
26+ from pandas ._typing import (
27+ TimestampNonexistent ,
28+ TimeUnit ,
29+ )
2730
2831_TimeZones : TypeAlias = str | _tzinfo | None | int
2932
@@ -235,5 +238,5 @@ class Timestamp(datetime):
235238 @property
236239 def daysinmonth (self ) -> int : ...
237240 @property
238- def unit (self ) -> str : ...
239- def as_unit (self , unit : str , round_ok : bool = ...) -> Timestamp : ...
241+ def unit (self ) -> TimeUnit : ...
242+ def as_unit (self , unit : TimeUnit , round_ok : bool = ...) -> Timestamp : ...
Original file line number Diff line number Diff line change 8585 IntervalClosedType ,
8686 Ordered ,
8787 Scalar ,
88+ TimeUnit ,
8889 npt ,
8990 type_t ,
9091 )
@@ -820,7 +821,7 @@ def _creso(self) -> int:
820821 return abbrev_to_npy_unit (self .unit )
821822
822823 @property
823- def unit (self ) -> str_type :
824+ def unit (self ) -> TimeUnit :
824825 """
825826 The precision of the datetime data.
826827
Original file line number Diff line number Diff line change 1515 Concatenate ,
1616 Literal ,
1717 Self ,
18+ cast ,
1819 final ,
1920 overload ,
2021)
9596 NDFrameT ,
9697 QuantileInterpolation ,
9798 P ,
99+ TimeUnit ,
98100 T ,
99101 WindowingRankType ,
100102 npt ,
@@ -2001,6 +2003,7 @@ def _validate(self) -> None:
20012003 except TypeError :
20022004 # if not a datetime dtype, eg for empty dataframes
20032005 unit = "ns"
2006+ unit = cast ("TimeUnit" , unit )
20042007 self ._win_freq_i8 = Timedelta (freq .nanos ).as_unit (unit )._value
20052008
20062009 # min_periods must be an integer
You can’t perform that action at this time.
0 commit comments