Skip to content

BUG: mixed column selection with dups is buggy (GH5639) #5640

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
Dec 4, 2013
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
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ Bug Fixes
- Fixed segfault on ``isnull(MultiIndex)`` (now raises an error instead)
(:issue:`5123`, :issue:`5125`)
- Allow duplicate indices when performing operations that align
(:issue:`5185`)
(:issue:`5185`, :issue:`5639`)
- Compound dtypes in a constructor raise ``NotImplementedError``
(:issue:`5191`)
- Bug in comparing duplicate frames (:issue:`4421`) related
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ def reindex_items_from(self, new_ref_items, indexer=None, method=None,
else:

masked_idx = indexer[indexer != -1]
new_items = self.items.take(masked_idx)
new_values = com.take_nd(self.values, masked_idx, axis=0,
allow_fill=False)
new_items = self.items.take(masked_idx)

# fill if needed
if needs_fill:
new_values = com.interpolate_2d(new_values, method=method,
Expand Down Expand Up @@ -3192,7 +3191,8 @@ def reindex_items(self, new_items, indexer=None, copy=True,
else:

# unique
if self.axes[0].is_unique:
if self.axes[0].is_unique and new_items.is_unique:

for block in self.blocks:

newb = block.reindex_items_from(new_items, copy=copy)
Expand All @@ -3201,7 +3201,7 @@ def reindex_items(self, new_items, indexer=None, copy=True,

# non-unique
else:
rl = self._set_ref_locs()
rl = self._set_ref_locs(do_refs='force')
for i, idx in enumerate(indexer):
blk, lidx = rl[idx]
item = new_items.take([i])
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,15 @@ def check(result, expected=None):
expected = DataFrame([[False,True],[True,False],[False,False],[True,False]],columns=['A','A'])
assert_frame_equal(result,expected)

# mixed column selection
# GH 5639
dfbool = DataFrame({'one' : Series([True, True, False], index=['a', 'b', 'c']),
'two' : Series([False, False, True, False], index=['a', 'b', 'c', 'd']),
'three': Series([False, True, True, True], index=['a', 'b', 'c', 'd'])})
expected = pd.concat([dfbool['one'],dfbool['three'],dfbool['one']],axis=1)
result = dfbool[['one', 'three', 'one']]
check(result,expected)

def test_insert_benchmark(self):
# from the vb_suite/frame_methods/frame_insert_columns
N = 10
Expand Down