Skip to content

Commit 0dfa193

Browse files
committed
Merge pull request #6786 from jreback/set_index
BUG: Bug in setting a tz-aware index directly via .index (GH6785)
2 parents 8120a59 + 61eac3d commit 0dfa193

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ Bug Fixes
301301
- Bug in downcasting inference with empty arrays (:issue:`6733`)
302302
- Bug in ``obj.blocks`` on sparse containers dropping all but the last items of same for dtype (:issue:`6748`)
303303
- Bug in unpickling ``NaT (NaTType)`` (:issue:`4606`)
304+
- Bug in setting a tz-aware index directly via ``.index`` (:issue:`6785`)
304305

305306
pandas 0.13.1
306307
-------------

pandas/core/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __new__(cls, data, dtype=None, copy=False, name=None, fastpath=False,
154154
if (inferred.startswith('datetime') or
155155
tslib.is_timestamp_array(subarr)):
156156
from pandas.tseries.index import DatetimeIndex
157-
return DatetimeIndex(data, copy=copy, name=name, **kwargs)
157+
return DatetimeIndex(subarr, copy=copy, name=name, **kwargs)
158158
elif inferred == 'period':
159159
return PeriodIndex(subarr, name=name, **kwargs)
160160

pandas/tests/test_frame.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,15 @@ def test_set_index_cast_datetimeindex(self):
21252125
result = df['D']
21262126
assert_series_equal(result, expected)
21272127

2128+
# GH 6785
2129+
# set the index manually
2130+
import pytz
2131+
df = DataFrame([{'ts':datetime(2014, 4, 1, tzinfo=pytz.utc), 'foo':1}])
2132+
expected = df.set_index('ts')
2133+
df.index = df['ts']
2134+
df.pop('ts')
2135+
assert_frame_equal(df, expected)
2136+
21282137
def test_set_index_multiindexcolumns(self):
21292138
columns = MultiIndex.from_tuples([('foo', 1), ('foo', 2), ('bar', 1)])
21302139
df = DataFrame(np.random.randn(3, 3), columns=columns)

0 commit comments

Comments
 (0)