@@ -442,53 +442,53 @@ def _generate_range(
442
442
end = end .tz_localize (None )
443
443
444
444
if isinstance (freq , Tick ):
445
- values = generate_regular_range (start , end , periods , freq )
445
+ i8values = generate_regular_range (start , end , periods , freq )
446
446
else :
447
447
xdr = generate_range (start = start , end = end , periods = periods , offset = freq )
448
- values = np .array ([x .value for x in xdr ], dtype = np .int64 )
448
+ i8values = np .array ([x .value for x in xdr ], dtype = np .int64 )
449
449
450
- _tz = start .tz if start is not None else end .tz
451
- values = values .view ("M8[ns]" )
452
- index = cls ._simple_new (values , freq = freq , dtype = tz_to_dtype (_tz ))
450
+ endpoint_tz = start .tz if start is not None else end .tz
453
451
454
- if tz is not None and index . tz is None :
455
- arr = tzconversion .tz_localize_to_utc (
456
- index . asi8 , tz , ambiguous = ambiguous , nonexistent = nonexistent
452
+ if tz is not None and endpoint_tz is None :
453
+ i8values = tzconversion .tz_localize_to_utc (
454
+ i8values , tz , ambiguous = ambiguous , nonexistent = nonexistent
457
455
)
458
456
459
- index = cls (arr )
460
-
461
- # index is localized datetime64 array -> have to convert
457
+ # i8values is localized datetime64 array -> have to convert
462
458
# start/end as well to compare
463
459
if start is not None :
464
- start = start .tz_localize (tz , ambiguous , nonexistent ). asm8
460
+ start = start .tz_localize (tz , ambiguous , nonexistent )
465
461
if end is not None :
466
- end = end .tz_localize (tz , ambiguous , nonexistent ). asm8
462
+ end = end .tz_localize (tz , ambiguous , nonexistent )
467
463
else :
468
464
# Create a linearly spaced date_range in local time
469
465
# Nanosecond-granularity timestamps aren't always correctly
470
466
# representable with doubles, so we limit the range that we
471
467
# pass to np.linspace as much as possible
472
- arr = (
468
+ i8values = (
473
469
np .linspace (0 , end .value - start .value , periods , dtype = "int64" )
474
470
+ start .value
475
471
)
476
- dtype = tz_to_dtype (tz )
477
- arr = arr .astype ("M8[ns]" , copy = False )
478
- index = cls ._simple_new (arr , freq = None , dtype = dtype )
472
+ if i8values .dtype != "i8" :
473
+ # 2022-01-09 I (brock) am not sure if it is possible for this
474
+ # to overflow and cast to e.g. f8, but if it does we need to cast
475
+ i8values = i8values .astype ("i8" )
479
476
480
477
if start == end :
481
478
if not left_inclusive and not right_inclusive :
482
- index = index [1 :- 1 ]
479
+ i8values = i8values [1 :- 1 ]
483
480
else :
481
+ start_i8 = Timestamp (start ).value
482
+ end_i8 = Timestamp (end ).value
484
483
if not left_inclusive or not right_inclusive :
485
- if not left_inclusive and len (index ) and index [0 ] == start :
486
- index = index [1 :]
487
- if not right_inclusive and len (index ) and index [- 1 ] == end :
488
- index = index [:- 1 ]
484
+ if not left_inclusive and len (i8values ) and i8values [0 ] == start_i8 :
485
+ i8values = i8values [1 :]
486
+ if not right_inclusive and len (i8values ) and i8values [- 1 ] == end_i8 :
487
+ i8values = i8values [:- 1 ]
489
488
489
+ dt64_values = i8values .view ("datetime64[ns]" )
490
490
dtype = tz_to_dtype (tz )
491
- return cls ._simple_new (index . _ndarray , freq = freq , dtype = dtype )
491
+ return cls ._simple_new (dt64_values , freq = freq , dtype = dtype )
492
492
493
493
# -----------------------------------------------------------------
494
494
# DatetimeLike Interface
0 commit comments