Skip to content

Commit 1296a5f

Browse files
committed
tz_localize_to_utc generates an array not DTI
1 parent ee1bcba commit 1296a5f

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
@@ -548,7 +548,6 @@ def _generate(cls, start, end, periods, name, freq,
548548
freq=freq, name=name)
549549
else:
550550
index = _generate_regular_range(start, end, periods, freq)
551-
552551
else:
553552

554553
if tz is not None:
@@ -572,12 +571,13 @@ def _generate(cls, start, end, periods, name, freq,
572571
freq=freq, name=name)
573572
else:
574573
index = _generate_regular_range(start, end, periods, freq)
575-
576574
if tz is not None and getattr(index, 'tz', None) is None:
577-
index = conversion.tz_localize_to_utc(_ensure_int64(index),
578-
tz,
579-
ambiguous=ambiguous)
580-
index = index.view(_NS_DTYPE)
575+
arr = conversion.tz_localize_to_utc(_ensure_int64(index),
576+
tz,
577+
ambiguous=ambiguous)
578+
579+
arr = arr.view(_NS_DTYPE)
580+
index = DatetimeIndex(arr)
581581

582582
# index is localized datetime64 array -> have to convert
583583
# start/end as well to compare
@@ -598,7 +598,9 @@ def _generate(cls, start, end, periods, name, freq,
598598
index = index[1:]
599599
if not right_closed and len(index) and index[-1] == end:
600600
index = index[:-1]
601-
index = cls._simple_new(index, name=name, freq=freq, tz=tz)
601+
602+
index = cls._simple_new(index.values, name=name, freq=freq, tz=tz)
603+
602604
return index
603605

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

635-
if isinstance(values, DatetimeIndex):
636-
values = values.values
637-
638637
if getattr(values, 'dtype', None) is None:
639638
# empty, but with dtype compat
640639
if values is None:

0 commit comments

Comments
 (0)