Skip to content

Commit 15e9401

Browse files
conquistador1492jreback
authored andcommitted
BUG: Copy index(GH 13522) (pandas-dev#14005)
1 parent 7c0b742 commit 15e9401

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ Bug Fixes
907907
- Bug in ``io.json.json_normalize()``, where non-ascii keys raised an exception (:issue:`13213`)
908908
- Bug when passing a not-default-indexed ``Series`` as ``xerr`` or ``yerr`` in ``.plot()`` (:issue:`11858`)
909909
- Bug in area plot draws legend incorrectly if subplot is enabled or legend is moved after plot (matplotlib 1.5.0 is required to draw area plot legend properly) (issue:`9161`, :issue:`13544`)
910+
- Bug in ``DataFrame`` assignment with an object-dtyped ``Index`` where the resultant column is mutable to the original object. (:issue:`13522`)
910911
- Bug in matplotlib ``AutoDataFormatter``; this restores the second scaled formatting and re-adds micro-second scaled formatting (:issue:`13131`)
911912
- Bug in selection from a ``HDFStore`` with a fixed format and ``start`` and/or ``stop`` specified will now return the selected range (:issue:`8287`)
912913
- Bug in ``Series`` construction from a tuple of integers on windows not returning default dtype (int64) (:issue:`13646`)

pandas/core/frame.py

+2
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,8 @@ def reindexer(value):
26382638
value = com._asarray_tuplesafe(value)
26392639
elif value.ndim == 2:
26402640
value = value.copy().T
2641+
elif isinstance(value, Index):
2642+
value = value.copy(deep=True)
26412643
else:
26422644
value = value.copy()
26432645

pandas/tests/frame/test_mutate_columns.py

+7
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ def test_insert(self):
156156
df.insert(0, 'baz', df['c'])
157157
self.assertEqual(df.columns.name, 'some_name')
158158

159+
# GH 13522
160+
df = DataFrame(index=['A', 'B', 'C'])
161+
df['X'] = df.index
162+
df['X'] = ['x', 'y', 'z']
163+
exp = DataFrame(data={'X': ['x', 'y', 'z']}, index=['A', 'B', 'C'])
164+
assert_frame_equal(df, exp)
165+
159166
def test_delitem(self):
160167
del self.frame['A']
161168
self.assertNotIn('A', self.frame)

0 commit comments

Comments
 (0)