Skip to content

BUG: Bug in list-like indexing with a mixed-integer Index, #11320 #11322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)



Expand Down
6 changes: 2 additions & 4 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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