Repository: pandas-dev/pandas

Issue:
Selecting same column twice in DataFrame does not work when some columns are bool
It works fine to select a column twice if the DataFrame does not consists of any columns of dtype bool, but works fine otherwise. 

``` python
import pandas as pd

#Data with just bool columns
dbool = {'one' : pd.Series([True, True, False], index=['a', 'b', 'c']),
    'two' : pd.Series([False, False, True, False], index=['a', 'b', 'c', 'd']),
    'three': pd.Series([False, True, True, True], index=['a', 'b', 'c', 'd'])}

#No bool columns
dnum = {'four' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
    'five' : pd.Series([1., 2., 3., 0.4], index=['a', 'b', 'c', 'd']),
    'six': pd.Series([9., 5., 4., -0.1], index=['a', 'b', 'c', 'd'])}

#data with both bool and non-bool columns
dmixed = {'one' : pd.Series([True, True, False], index=['a', 'b', 'c']),
    'two' : pd.Series([False, False, True, False], index=['a', 'b', 'c', 'd']),
    'three': pd.Series([False, True, True, True], index=['a', 'b', 'c', 'd']),
    'four' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
    'five' : pd.Series([1., 2., 3., 0.4], index=['a', 'b', 'c', 'd']),
    'six': pd.Series([9., 5., 4., -0.1], index=['a', 'b', 'c', 'd'])}

dfbool = pd.DataFrame(dbool)
dfnum = pd.DataFrame(dnum)  
dfmixed = pd.DataFrame(dmixed)

#Works fine
dfnum[['four', 'five', 'four']]

#Does not work
dfbool[['one', 'three', 'one']]

#Does not work
dfmixed[['four', 'five', 'four']]
dfmixed[['one', 'three', 'one']]
dfmixed[['one', 'four', 'one']]
```



Discussion:

Resolving patch:
diff --git a/pandas/core/internals.py b/pandas/core/internals.py
--- a/pandas/core/internals.py
+++ b/pandas/core/internals.py
@@ -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,
@@ -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)
@@ -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])


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -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