From 32723c5db04e4b80dc40a32037305ddd835e8155 Mon Sep 17 00:00:00 2001 From: jreback Date: Sun, 16 Feb 2014 19:08:18 -0500 Subject: [PATCH] BUG: Bug in take with duplicate columns not consolidated (GH6240) --- doc/source/release.rst | 1 + pandas/core/internals.py | 5 +++++ pandas/tests/test_frame.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/doc/source/release.rst b/doc/source/release.rst index e489e872a92ec..8b753abc83ca7 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -118,6 +118,7 @@ Bug Fixes - Disabled clipboard tests until release time (run locally with ``nosetests -A disabled`` (:issue:`6048`). - Bug in ``DataFrame.replace()`` when passing a nested ``dict`` that contained keys not in the values to be replaced (:issue:`6342`) +- Bug in take with duplicate columns not consolidated (:issue:`6240`) pandas 0.13.1 ------------- diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 94d0deaec80e3..c89aac0fa7923 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -3399,6 +3399,11 @@ def reindex_items(self, new_items, indexer=None, copy=True, new_blocks.append(na_block) new_blocks = _consolidate(new_blocks, new_items) + # consolidate + # import for non-unique which creates a block for each item + # and they must be consolidated before passing on + new_blocks = _consolidate(new_blocks, new_items) + return self.__class__(new_blocks, new_axes) def _make_na_block(self, items, ref_items, placement=None, diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 6262a354065d2..6eddd52dba634 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -3243,6 +3243,19 @@ def check(result, expected=None): df['that'] = 1 check(df, expected) + def test_column_dups2(self): + + # drop buggy GH 6240 + df = DataFrame({'A' : np.random.randn(5), + 'B' : np.random.randn(5), + 'C' : np.random.randn(5), + 'D' : ['a','b','c','d','e'] }) + + expected = df.take([0,1,1], axis=1) + df2 = df.take([2,0,1,2,1], axis=1) + result = df2.drop('C',axis=1) + assert_frame_equal(result, expected) + def test_column_dups_indexing(self): def check(result, expected=None):