Skip to content

BUG: Fix incorrect _is_scalar_access check in iloc #32085

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 3 commits into from
Feb 22, 2020
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
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3467,13 +3467,13 @@ def _get_item_cache(self, item):
res._is_copy = self._is_copy
return res

def _iget_item_cache(self, item):
def _iget_item_cache(self, item: int):
"""Return the cached item, item represents a positional indexer."""
ax = self._info_axis
if ax.is_unique:
lower = self._get_item_cache(ax[item])
else:
lower = self._take_with_is_copy(item, axis=self._info_axis_number)
return self._ixs(item, axis=1)
return lower

def _box_item_values(self, key, values):
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,10 +1445,6 @@ def _is_scalar_access(self, key: Tuple) -> bool:
if not is_integer(k):
return False

ax = self.obj.axes[i]
if not ax.is_unique:
return False

return True

def _validate_integer(self, key: int, axis: int) -> None:
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def test_iloc_getitem_list_int(self):

class TestiLoc2:
# TODO: better name, just separating out things that dont rely on base class

def test_is_scalar_access(self):
# GH#32085 index with duplicates doesnt matter for _is_scalar_access
index = pd.Index([1, 2, 1])
ser = pd.Series(range(3), index=index)

assert ser.iloc._is_scalar_access((1,))

df = ser.to_frame()
assert df.iloc._is_scalar_access((1, 0,))

def test_iloc_exceeds_bounds(self):

# GH6296
Expand Down