Skip to content

Commit a6a038b

Browse files
committed
tz_localize_to_utc generates an array not DTI
1 parent 92416a6 commit a6a038b

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
@@ -525,7 +525,6 @@ def _generate(cls, start, end, periods, name, freq,
525525
freq=freq, name=name)
526526
else:
527527
index = _generate_regular_range(start, end, periods, freq)
528-
529528
else:
530529

531530
if tz is not None:
@@ -549,12 +548,13 @@ def _generate(cls, start, end, periods, name, freq,
549548
freq=freq, name=name)
550549
else:
551550
index = _generate_regular_range(start, end, periods, freq)
552-
553551
if tz is not None and getattr(index, 'tz', None) is None:
554-
index = conversion.tz_localize_to_utc(_ensure_int64(index),
555-
tz,
556-
ambiguous=ambiguous)
557-
index = index.view(_NS_DTYPE)
552+
arr = conversion.tz_localize_to_utc(_ensure_int64(index),
553+
tz,
554+
ambiguous=ambiguous)
555+
556+
arr = arr.view(_NS_DTYPE)
557+
index = DatetimeIndex(arr)
558558

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

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

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

0 commit comments

Comments
 (0)