Skip to content

Commit 28342a9

Browse files
committed
tz_localize_to_utc generates an array not DTI
1 parent 293c9a0 commit 28342a9

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
@@ -527,7 +527,6 @@ def _generate(cls, start, end, periods, name, freq,
527527
freq=freq, name=name)
528528
else:
529529
index = _generate_regular_range(start, end, periods, freq)
530-
531530
else:
532531

533532
if tz is not None:
@@ -551,12 +550,13 @@ def _generate(cls, start, end, periods, name, freq,
551550
freq=freq, name=name)
552551
else:
553552
index = _generate_regular_range(start, end, periods, freq)
554-
555553
if tz is not None and getattr(index, 'tz', None) is None:
556-
index = conversion.tz_localize_to_utc(_ensure_int64(index),
557-
tz,
558-
ambiguous=ambiguous)
559-
index = index.view(_NS_DTYPE)
554+
arr = conversion.tz_localize_to_utc(_ensure_int64(index),
555+
tz,
556+
ambiguous=ambiguous)
557+
558+
arr = arr.view(_NS_DTYPE)
559+
index = DatetimeIndex(arr)
560560

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

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

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

0 commit comments

Comments
 (0)