Skip to content

Commit 0bf9f14

Browse files
mroeschkejreback
authored andcommitted
BUG: DatetimeIndex.to_frame does not drop timezone information (#25811)
1 parent cdfdd77 commit 0bf9f14

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ Timedelta
208208
Timezones
209209
^^^^^^^^^
210210

211+
- Bug in :func:`DatetimeIndex.to_frame` where timezone aware data would be converted to timezone naive data (:issue:`25809`)
211212
- Bug in :func:`to_datetime` with ``utc=True`` and datetime strings that would apply previously parsed UTC offsets to subsequent arguments (:issue:`24992`)
212213
- Bug in :func:`Timestamp.tz_localize` and :func:`Timestamp.tz_convert` does not propagate ``freq`` (:issue:`25241`)
213214
- Bug in :func:`Series.at` where setting :class:`Timestamp` with timezone raises ``TypeError`` (:issue:`25506`)

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ def to_frame(self, index=True, name=None):
12081208
from pandas import DataFrame
12091209
if name is None:
12101210
name = self.name or 0
1211-
result = DataFrame({name: self.values.copy()})
1211+
result = DataFrame({name: self._values.copy()})
12121212

12131213
if index:
12141214
result.index = self

pandas/tests/indexes/common.py

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def test_to_frame(self, name):
8585
df = idx.to_frame(index=False, name=idx_name)
8686
assert df.index is not idx
8787

88+
def test_to_frame_datetime_tz(self):
89+
# GH 25809
90+
idx = pd.date_range(start='2019-01-01', end='2019-01-30', freq='D')
91+
idx = idx.tz_localize('UTC')
92+
result = idx.to_frame()
93+
expected = pd.DataFrame(idx, index=idx)
94+
tm.assert_frame_equal(result, expected)
95+
8896
def test_shift(self):
8997

9098
# GH8083 test the base class for shift

0 commit comments

Comments
 (0)