Repository: pandas-dev/pandas

Issue:
BUG: iloc getitem with DataFrame with MultiIndex
```
import pandas as pd
import numpy as np

tup = zip(*[['a','a','b','b'],['x','y','x','y']])
index = pd.MultiIndex.from_tuples(tup)
df = pd.DataFrame(np.random.randn(4, 4), index=index)
df.iloc[[0, 1]]
```

This will raise:

```
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long'
```

I am using 0.12 version.



Discussion:

Resolving patch:
diff --git a/pandas/core/index.py b/pandas/core/index.py
--- a/pandas/core/index.py
+++ b/pandas/core/index.py
@@ -2826,6 +2826,11 @@ def reindex(self, target, method=None, level=None, limit=None,
         -------
         (new_index, indexer, mask) : (MultiIndex, ndarray, ndarray)
         """
+
+        # a direct takeable
+        if takeable:
+            return self.take(target), target
+
         if level is not None:
             if method is not None:
                 raise TypeError('Fill method not supported if level passed')


Test patch:
diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py
--- a/pandas/tests/test_indexing.py
+++ b/pandas/tests/test_indexing.py
@@ -389,6 +389,37 @@ def test_iloc_getitem_slice_dups(self):
         assert_frame_equal(df.iloc[10:,:2],df2)
         assert_frame_equal(df.iloc[10:,2:],df1)
 
+    def test_iloc_getitem_multiindex(self):
+
+        df = DataFrame(np.random.randn(3, 3),
+                       columns=[[2,2,4],[6,8,10]],
+                       index=[[4,4,8],[8,10,12]])
+
+        rs = df.iloc[2]
+        xp = df.irow(2)
+        assert_series_equal(rs, xp)
+
+        rs = df.iloc[:,2]
+        xp = df.icol(2)
+        assert_series_equal(rs, xp)
+
+        rs = df.iloc[2,2]
+        xp = df.values[2,2]
+        self.assert_(rs == xp)
+
+        # for multiple items
+        # GH 5528
+        rs = df.iloc[[0,1]]
+        xp = df.xs(4,drop_level=False)
+        assert_frame_equal(rs,xp)
+
+        tup = zip(*[['a','a','b','b'],['x','y','x','y']])
+        index = MultiIndex.from_tuples(tup)
+        df = DataFrame(np.random.randn(4, 4), index=index)
+        rs = df.iloc[[2, 3]]
+        xp = df.xs('b',drop_level=False)
+        assert_frame_equal(rs,xp)
+
     def test_iloc_getitem_out_of_bounds(self):
 
         # out-of-bounds slice
@@ -409,23 +440,6 @@ def test_iloc_setitem(self):
         result = df.iloc[:,2:3]
         assert_frame_equal(result, expected)
 
-    def test_iloc_multiindex(self):
-        df = DataFrame(np.random.randn(3, 3),
-                       columns=[[2,2,4],[6,8,10]],
-                       index=[[4,4,8],[8,10,12]])
-
-        rs = df.iloc[2]
-        xp = df.irow(2)
-        assert_series_equal(rs, xp)
-
-        rs = df.iloc[:,2]
-        xp = df.icol(2)
-        assert_series_equal(rs, xp)
-
-        rs = df.iloc[2,2]
-        xp = df.values[2,2]
-        self.assert_(rs == xp)
-
     def test_loc_getitem_int(self):
 
         # int label
@@ -704,7 +718,7 @@ def test_iloc_setitem_series(self):
         result = s.iloc[:4]
         assert_series_equal(result, expected)
 
-    def test_iloc_multiindex(self):
+    def test_iloc_getitem_multiindex(self):
         mi_labels = DataFrame(np.random.randn(4, 3), columns=[['i', 'i', 'j'],
                                                               ['A', 'A', 'B']],
                               index=[['i', 'i', 'j', 'k'], ['X', 'X', 'Y','Y']])