7373 DtypeObj ,
7474 NpDtype ,
7575 npt ,
76+ TimeUnit ,
7677 )
7778
7879 from pandas import DataFrame
@@ -275,7 +276,7 @@ def _from_sequence_not_strict(
275276
276277 @classmethod
277278 def _generate_range (
278- cls , start , end , periods , freq , closed = None , * , unit : str | None = None
279+ cls , start , end , periods , freq , closed = None , * , unit : TimeUnit
279280 ) -> Self :
280281 periods = dtl .validate_periods (periods )
281282 if freq is None and any (x is None for x in [periods , start , end ]):
@@ -293,11 +294,8 @@ def _generate_range(
293294 if end is not None :
294295 end = Timedelta (end ).as_unit ("ns" )
295296
296- if unit is not None :
297- if unit not in ["s" , "ms" , "us" , "ns" ]:
298- raise ValueError ("'unit' must be one of 's', 'ms', 'us', 'ns'" )
299- else :
300- unit = "ns"
297+ if unit not in ["s" , "ms" , "us" , "ns" ]:
298+ raise ValueError ("'unit' must be one of 's', 'ms', 'us', 'ns'" )
301299
302300 if start is not None and unit is not None :
303301 start = start .as_unit (unit , round_ok = False )
@@ -327,7 +325,7 @@ def _unbox_scalar(self, value) -> np.timedelta64:
327325 raise ValueError ("'value' should be a Timedelta." )
328326 self ._check_compatible_with (value )
329327 if value is NaT :
330- return np .timedelta64 (value ._value , self .unit ) # type: ignore[call-overload]
328+ return np .timedelta64 (value ._value , self .unit )
331329 else :
332330 return value .as_unit (self .unit , round_ok = False ).asm8
333331
0 commit comments