Skip to content

BUG: Bug in take with duplicate columns not consolidated (GH6240) #6375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down