Skip to content

Commit e96869b

Browse files
committed
tz_localize_to_utc generates an array not DTI
1 parent b172de3 commit e96869b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ def _generate(cls, start, end, periods, name, freq,
538538
freq=freq, name=name)
539539
else:
540540
index = _generate_regular_range(start, end, periods, freq)
541-
542541
else:
543542

544543
if tz is not None:
@@ -562,12 +561,13 @@ def _generate(cls, start, end, periods, name, freq,
562561
freq=freq, name=name)
563562
else:
564563
index = _generate_regular_range(start, end, periods, freq)
565-
566564
if tz is not None and getattr(index, 'tz', None) is None:
567-
index = conversion.tz_localize_to_utc(_ensure_int64(index),
568-
tz,
569-
ambiguous=ambiguous)
570-
index = index.view(_NS_DTYPE)
565+
arr = conversion.tz_localize_to_utc(_ensure_int64(index),
566+
tz,
567+
ambiguous=ambiguous)
568+
569+
arr = arr.view(_NS_DTYPE)
570+
index = DatetimeIndex(arr)
571571

572572
# index is localized datetime64 array -> have to convert
573573
# start/end as well to compare
@@ -588,7 +588,9 @@ def _generate(cls, start, end, periods, name, freq,
588588
index = index[1:]
589589
if not right_closed and len(index) and index[-1] == end:
590590
index = index[:-1]
591-
index = cls._simple_new(index, name=name, freq=freq, tz=tz)
591+
592+
index = cls._simple_new(index.values, name=name, freq=freq, tz=tz)
593+
592594
return index
593595

594596
@property
@@ -622,9 +624,6 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
622624
if we are passed a non-dtype compat, then coerce using the constructor
623625
"""
624626

625-
if isinstance(values, DatetimeIndex):
626-
values = values.values
627-
628627
if getattr(values, 'dtype', None) is None:
629628
# empty, but with dtype compat
630629
if values is None:

0 commit comments

Comments
 (0)