Skip to content

Commit 85c62b1

Browse files
committed
BUG: Bug in list-like indexing with a mixed-integer Index, pandas-dev#11320
1 parent 51a70dc commit 85c62b1

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

doc/source/whatsnew/v0.17.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Bug Fixes
6565
- Bug in tz-conversions with an ambiguous time and ``.dt`` accessors (:issues:`11295`)
6666

6767

68-
68+
- Bug in list-like indexing with a mixed-integer Index (:issue:`11320`)
6969

7070

7171

pandas/core/index.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,6 @@ def _convert_list_indexer(self, keyarr, kind=None):
982982
if kind in [None, 'iloc', 'ix'] and is_integer_dtype(keyarr) \
983983
and not self.is_floating() and not isinstance(keyarr, ABCPeriodIndex):
984984

985-
if self.inferred_type != 'integer':
986-
keyarr = np.where(keyarr < 0,
987-
len(self) + keyarr, keyarr)
988-
989985
if self.inferred_type == 'mixed-integer':
990986
indexer = self.get_indexer(keyarr)
991987
if (indexer >= 0).all():
@@ -998,6 +994,8 @@ def _convert_list_indexer(self, keyarr, kind=None):
998994
return maybe_convert_indices(indexer, len(self))
999995

1000996
elif not self.inferred_type == 'integer':
997+
keyarr = np.where(keyarr < 0,
998+
len(self) + keyarr, keyarr)
1001999
return keyarr
10021000

10031001
return None

pandas/tests/test_frame.py

+12
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,18 @@ def test_getitem_ix_mixed_integer(self):
488488
expected = df.ix[Index([1, 10], dtype=object)]
489489
assert_frame_equal(result, expected)
490490

491+
# 11320
492+
df = pd.DataFrame({ "rna": (1.5,2.2,3.2,4.5),
493+
-1000: [11,21,36,40],
494+
0: [10,22,43,34],
495+
1000:[0, 10, 20, 30] },columns=['rna',-1000,0,1000])
496+
result = df[[1000]]
497+
expected = df.iloc[:,[3]]
498+
assert_frame_equal(result, expected)
499+
result = df[[-1000]]
500+
expected = df.iloc[:,[1]]
501+
assert_frame_equal(result, expected)
502+
491503
def test_getitem_setitem_ix_negative_integers(self):
492504
result = self.frame.ix[:, -1]
493505
assert_series_equal(result, self.frame['D'])

0 commit comments

Comments
 (0)