Skip to content

Commit 5b0b256

Browse files
committed
tz_localize_to_utc generates an array not DTI
1 parent d2fdbb5 commit 5b0b256

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
@@ -526,7 +526,6 @@ def _generate(cls, start, end, periods, name, freq,
526526
freq=freq, name=name)
527527
else:
528528
index = _generate_regular_range(start, end, periods, freq)
529-
530529
else:
531530

532531
if tz is not None:
@@ -550,12 +549,13 @@ def _generate(cls, start, end, periods, name, freq,
550549
freq=freq, name=name)
551550
else:
552551
index = _generate_regular_range(start, end, periods, freq)
553-
554552
if tz is not None and getattr(index, 'tz', None) is None:
555-
index = conversion.tz_localize_to_utc(_ensure_int64(index),
556-
tz,
557-
ambiguous=ambiguous)
558-
index = index.view(_NS_DTYPE)
553+
arr = conversion.tz_localize_to_utc(_ensure_int64(index),
554+
tz,
555+
ambiguous=ambiguous)
556+
557+
arr = arr.view(_NS_DTYPE)
558+
index = DatetimeIndex(arr)
559559

560560
# index is localized datetime64 array -> have to convert
561561
# start/end as well to compare
@@ -576,7 +576,9 @@ def _generate(cls, start, end, periods, name, freq,
576576
index = index[1:]
577577
if not right_closed and len(index) and index[-1] == end:
578578
index = index[:-1]
579-
index = cls._simple_new(index, name=name, freq=freq, tz=tz)
579+
580+
index = cls._simple_new(index.values, name=name, freq=freq, tz=tz)
581+
580582
return index
581583

582584
def _convert_for_op(self, value):
@@ -599,9 +601,6 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
599601
if we are passed a non-dtype compat, then coerce using the constructor
600602
"""
601603

602-
if isinstance(values, DatetimeIndex):
603-
values = values.values
604-
605604
if getattr(values, 'dtype', None) is None:
606605
# empty, but with dtype compat
607606
if values is None:

0 commit comments

Comments
 (0)