diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py old mode 100644 new mode 100755 index a7cc3b9dddd36..35fcf0d49d0d6 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -903,7 +903,9 @@ def _getitem_lowerdim(self, tup): # we maybe be using a tuple to represent multiple dimensions here ax0 = self.obj._get_axis(0) - if isinstance(ax0, MultiIndex): + # ...but iloc should handle the tuple as simple integer-location + # instead of checking it as multiindex representation (GH 13797) + if isinstance(ax0, MultiIndex) and self.name != 'iloc': result = self._handle_lowerdim_multi_index_axis0(tup) if result is not None: return result diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py old mode 100644 new mode 100755 index f3b0becccf596..370d7f720c0e0 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -2420,6 +2420,34 @@ def test_repeat(self): m_df = pd.Series(data, index=m_idx) assert m_df.repeat(3).shape == (3 * len(data), ) + def test_iloc_mi(self): + # GH 13797 + # Test if iloc can handle integer locations in MultiIndexed DataFrame + + data = [ + ['str00', 'str01'], + ['str10', 'str11'], + ['str20', 'srt21'], + ['str30', 'str31'], + ['str40', 'str41'] + ] + + mi = pd.MultiIndex.from_tuples( + [('CC', 'A'), + ('CC', 'B'), + ('CC', 'B'), + ('BB', 'a'), + ('BB', 'b') + ]) + + ans = pd.DataFrame(data) + df_mi = pd.DataFrame(data, index=mi) + + res = pd.DataFrame([[df_mi.iloc[r, c] for c in range(2)] + for r in range(5)]) + + assert_frame_equal(res, ans) + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],