Skip to content

Commit 6b0b72b

Browse files
committed
tz_localize_to_utc generates an array not DTI
1 parent 4505517 commit 6b0b72b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pandas/core/indexes/datetimes.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ def _generate(cls, start, end, periods, name, freq,
549549
freq=freq, name=name)
550550
else:
551551
index = _generate_regular_range(start, end, periods, freq)
552-
553552
else:
554553

555554
if tz is not None:
@@ -573,12 +572,13 @@ def _generate(cls, start, end, periods, name, freq,
573572
freq=freq, name=name)
574573
else:
575574
index = _generate_regular_range(start, end, periods, freq)
576-
577575
if tz is not None and getattr(index, 'tz', None) is None:
578-
index = conversion.tz_localize_to_utc(_ensure_int64(index),
579-
tz,
580-
ambiguous=ambiguous)
581-
index = index.view(_NS_DTYPE)
576+
arr = conversion.tz_localize_to_utc(_ensure_int64(index),
577+
tz,
578+
ambiguous=ambiguous)
579+
580+
arr = arr.view(_NS_DTYPE)
581+
index = DatetimeIndex(arr)
582582

583583
# index is localized datetime64 array -> have to convert
584584
# start/end as well to compare
@@ -596,7 +596,9 @@ def _generate(cls, start, end, periods, name, freq,
596596
index = index[1:]
597597
if not right_closed and len(index) and index[-1] == end:
598598
index = index[:-1]
599-
index = cls._simple_new(index, name=name, freq=freq, tz=tz)
599+
600+
index = cls._simple_new(index.values, name=name, freq=freq, tz=tz)
601+
600602
return index
601603

602604
@property
@@ -630,9 +632,6 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
630632
if we are passed a non-dtype compat, then coerce using the constructor
631633
"""
632634

633-
if isinstance(values, DatetimeIndex):
634-
values = values.values
635-
636635
if getattr(values, 'dtype', None) is None:
637636
# empty, but with dtype compat
638637
if values is None:

0 commit comments

Comments
 (0)