diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index 507c829e5763f..86f6a85898a15 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -65,7 +65,7 @@ Bug Fixes - Bug in tz-conversions with an ambiguous time and ``.dt`` accessors (:issues:`11295`) - +- Bug in list-like indexing with a mixed-integer Index (:issue:`11320`) diff --git a/pandas/core/index.py b/pandas/core/index.py index 256ece6539b6f..b4c690fe8973b 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -982,10 +982,6 @@ def _convert_list_indexer(self, keyarr, kind=None): if kind in [None, 'iloc', 'ix'] and is_integer_dtype(keyarr) \ and not self.is_floating() and not isinstance(keyarr, ABCPeriodIndex): - if self.inferred_type != 'integer': - keyarr = np.where(keyarr < 0, - len(self) + keyarr, keyarr) - if self.inferred_type == 'mixed-integer': indexer = self.get_indexer(keyarr) if (indexer >= 0).all(): @@ -998,6 +994,8 @@ def _convert_list_indexer(self, keyarr, kind=None): return maybe_convert_indices(indexer, len(self)) elif not self.inferred_type == 'integer': + keyarr = np.where(keyarr < 0, + len(self) + keyarr, keyarr) return keyarr return None diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 172c1e30686e1..6667d389bd6c5 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -488,6 +488,18 @@ def test_getitem_ix_mixed_integer(self): expected = df.ix[Index([1, 10], dtype=object)] assert_frame_equal(result, expected) + # 11320 + df = pd.DataFrame({ "rna": (1.5,2.2,3.2,4.5), + -1000: [11,21,36,40], + 0: [10,22,43,34], + 1000:[0, 10, 20, 30] },columns=['rna',-1000,0,1000]) + result = df[[1000]] + expected = df.iloc[:,[3]] + assert_frame_equal(result, expected) + result = df[[-1000]] + expected = df.iloc[:,[1]] + assert_frame_equal(result, expected) + def test_getitem_setitem_ix_negative_integers(self): result = self.frame.ix[:, -1] assert_series_equal(result, self.frame['D'])