Skip to content

Commit 9eace30

Browse files
committed
Merge pull request #6375 from jreback/take_dup
BUG: Bug in take with duplicate columns not consolidated (GH6240)
2 parents e5ff569 + 32723c5 commit 9eace30

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Bug Fixes
118118
- Disabled clipboard tests until release time (run locally with ``nosetests -A disabled`` (:issue:`6048`).
119119
- Bug in ``DataFrame.replace()`` when passing a nested ``dict`` that contained
120120
keys not in the values to be replaced (:issue:`6342`)
121+
- Bug in take with duplicate columns not consolidated (:issue:`6240`)
121122

122123
pandas 0.13.1
123124
-------------

pandas/core/internals.py

+5
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,11 @@ def reindex_items(self, new_items, indexer=None, copy=True,
33993399
new_blocks.append(na_block)
34003400
new_blocks = _consolidate(new_blocks, new_items)
34013401

3402+
# consolidate
3403+
# import for non-unique which creates a block for each item
3404+
# and they must be consolidated before passing on
3405+
new_blocks = _consolidate(new_blocks, new_items)
3406+
34023407
return self.__class__(new_blocks, new_axes)
34033408

34043409
def _make_na_block(self, items, ref_items, placement=None,

pandas/tests/test_frame.py

+13
Original file line numberDiff line numberDiff line change
@@ -3243,6 +3243,19 @@ def check(result, expected=None):
32433243
df['that'] = 1
32443244
check(df, expected)
32453245

3246+
def test_column_dups2(self):
3247+
3248+
# drop buggy GH 6240
3249+
df = DataFrame({'A' : np.random.randn(5),
3250+
'B' : np.random.randn(5),
3251+
'C' : np.random.randn(5),
3252+
'D' : ['a','b','c','d','e'] })
3253+
3254+
expected = df.take([0,1,1], axis=1)
3255+
df2 = df.take([2,0,1,2,1], axis=1)
3256+
result = df2.drop('C',axis=1)
3257+
assert_frame_equal(result, expected)
3258+
32463259
def test_column_dups_indexing(self):
32473260

32483261
def check(result, expected=None):

0 commit comments

Comments
 (0)