Skip to content

Commit

Permalink
Merge pull request #11322 from jreback/indexing
Browse files Browse the repository at this point in the history
BUG: Bug in list-like indexing with a mixed-integer Index, #11320
  • Loading branch information
jreback committed Oct 14, 2015
2 parents 9bcc1a8 + 85c62b1 commit a89b96d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.1.txt
Expand Up @@ -67,7 +67,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`)



Expand Down
6 changes: 2 additions & 4 deletions pandas/core/index.py
Expand Up @@ -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():
Expand 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
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_frame.py
Expand Up @@ -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'])
Expand Down

0 comments on commit a89b96d

Please sign in to comment.