@@ -405,7 +405,7 @@ def _generate_range( # type: ignore[override]
405
405
cls ,
406
406
start ,
407
407
end ,
408
- periods ,
408
+ periods : int | None ,
409
409
freq ,
410
410
tz = None ,
411
411
normalize : bool = False ,
@@ -441,9 +441,9 @@ def _generate_range( # type: ignore[override]
441
441
else :
442
442
unit = "ns"
443
443
444
- if start is not None and unit is not None :
444
+ if start is not None :
445
445
start = start .as_unit (unit , round_ok = False )
446
- if end is not None and unit is not None :
446
+ if end is not None :
447
447
end = end .as_unit (unit , round_ok = False )
448
448
449
449
left_inclusive , right_inclusive = validate_inclusive (inclusive )
@@ -452,14 +452,8 @@ def _generate_range( # type: ignore[override]
452
452
453
453
if tz is not None :
454
454
# Localize the start and end arguments
455
- start_tz = None if start is None else start .tz
456
- end_tz = None if end is None else end .tz
457
- start = _maybe_localize_point (
458
- start , start_tz , start , freq , tz , ambiguous , nonexistent
459
- )
460
- end = _maybe_localize_point (
461
- end , end_tz , end , freq , tz , ambiguous , nonexistent
462
- )
455
+ start = _maybe_localize_point (start , freq , tz , ambiguous , nonexistent )
456
+ end = _maybe_localize_point (end , freq , tz , ambiguous , nonexistent )
463
457
464
458
if freq is not None :
465
459
# We break Day arithmetic (fixed 24 hour) here and opt for
@@ -505,6 +499,7 @@ def _generate_range( # type: ignore[override]
505
499
# Nanosecond-granularity timestamps aren't always correctly
506
500
# representable with doubles, so we limit the range that we
507
501
# pass to np.linspace as much as possible
502
+ periods = cast (int , periods )
508
503
i8values = (
509
504
np .linspace (0 , end ._value - start ._value , periods , dtype = "int64" )
510
505
+ start ._value
@@ -2688,16 +2683,16 @@ def _maybe_normalize_endpoints(
2688
2683
return start , end
2689
2684
2690
2685
2691
- def _maybe_localize_point (ts , is_none , is_not_none , freq , tz , ambiguous , nonexistent ):
2686
+ def _maybe_localize_point (
2687
+ ts : Timestamp | None , freq , tz , ambiguous , nonexistent
2688
+ ) -> Timestamp | None :
2692
2689
"""
2693
2690
Localize a start or end Timestamp to the timezone of the corresponding
2694
2691
start or end Timestamp
2695
2692
2696
2693
Parameters
2697
2694
----------
2698
2695
ts : start or end Timestamp to potentially localize
2699
- is_none : argument that should be None
2700
- is_not_none : argument that should not be None
2701
2696
freq : Tick, DateOffset, or None
2702
2697
tz : str, timezone object or None
2703
2698
ambiguous: str, localization behavior for ambiguous times
@@ -2710,7 +2705,7 @@ def _maybe_localize_point(ts, is_none, is_not_none, freq, tz, ambiguous, nonexis
2710
2705
# Make sure start and end are timezone localized if:
2711
2706
# 1) freq = a Timedelta-like frequency (Tick)
2712
2707
# 2) freq = None i.e. generating a linspaced range
2713
- if is_none is None and is_not_none is not None :
2708
+ if ts is not None and ts . tzinfo is None :
2714
2709
# Note: We can't ambiguous='infer' a singular ambiguous time; however,
2715
2710
# we have historically defaulted ambiguous=False
2716
2711
ambiguous = ambiguous if ambiguous != "infer" else False
0 commit comments