Skip to content

Commit ebe4641

Browse files
committed
Merge pull request #6122 from jreback/dups
BUG: Bug in assignment with duplicate columns in a frame where the locations are a slice
2 parents a323cc9 + 4eba560 commit ebe4641

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Bug Fixes
157157
- Bug with insert of strings into DatetimeIndex (:issue:`5818`)
158158
- Fixed unicode bug in to_html/HTML repr (:issue:`6098`)
159159
- Fixed missing arg validation in get_options_data (:issue:`6105`)
160+
- Bug in assignment with duplicate columns in a frame where the locations
161+
are a slice (e.g. next to each other) (:issue:`6120`)
160162

161163
pandas 0.13.0
162164
-------------

pandas/core/internals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,7 @@ def _set_item(item, arr):
29692969
# we are inserting one by one, so the index can go from unique
29702970
# to non-unique during the loop, need to have _ref_locs defined
29712971
# at all times
2972-
if np.isscalar(item) and com.is_list_like(loc):
2972+
if np.isscalar(item) and (com.is_list_like(loc) or isinstance(loc, slice)):
29732973

29742974
# first delete from all blocks
29752975
self.delete(item)

pandas/tests/test_frame.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,6 +3229,21 @@ def check(result, expected=None):
32293229
result = getattr(df,op)(df)
32303230
check(result,expected)
32313231

3232+
# multiple assignments that change dtypes
3233+
# the location indexer is a slice
3234+
# GH 6120
3235+
df = DataFrame(np.random.randn(5,2), columns=['that', 'that'])
3236+
expected = DataFrame(1.0, index=range(5), columns=['that', 'that'])
3237+
3238+
df['that'] = 1.0
3239+
check(df, expected)
3240+
3241+
df = DataFrame(np.random.rand(5,2), columns=['that', 'that'])
3242+
expected = DataFrame(1, index=range(5), columns=['that', 'that'])
3243+
3244+
df['that'] = 1
3245+
check(df, expected)
3246+
32323247
def test_column_dups_indexing(self):
32333248

32343249
def check(result, expected=None):

0 commit comments

Comments
 (0)