Skip to content

Commit 54b7765

Browse files
jbrockmendelroberthdevries
authored andcommitted
BUG: Fix incorrect _is_scalar_access check in iloc (pandas-dev#32085)
1 parent b8786d3 commit 54b7765

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3467,13 +3467,13 @@ def _get_item_cache(self, item):
34673467
res._is_copy = self._is_copy
34683468
return res
34693469

3470-
def _iget_item_cache(self, item):
3470+
def _iget_item_cache(self, item: int):
34713471
"""Return the cached item, item represents a positional indexer."""
34723472
ax = self._info_axis
34733473
if ax.is_unique:
34743474
lower = self._get_item_cache(ax[item])
34753475
else:
3476-
lower = self._take_with_is_copy(item, axis=self._info_axis_number)
3476+
return self._ixs(item, axis=1)
34773477
return lower
34783478

34793479
def _box_item_values(self, key, values):

pandas/core/indexing.py

-4
Original file line numberDiff line numberDiff line change
@@ -1414,10 +1414,6 @@ def _is_scalar_access(self, key: Tuple) -> bool:
14141414
if not is_integer(k):
14151415
return False
14161416

1417-
ax = self.obj.axes[i]
1418-
if not ax.is_unique:
1419-
return False
1420-
14211417
return True
14221418

14231419
def _validate_integer(self, key: int, axis: int) -> None:

pandas/tests/indexing/test_iloc.py

+11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ def test_iloc_getitem_list_int(self):
4747

4848
class TestiLoc2:
4949
# TODO: better name, just separating out things that dont rely on base class
50+
51+
def test_is_scalar_access(self):
52+
# GH#32085 index with duplicates doesnt matter for _is_scalar_access
53+
index = pd.Index([1, 2, 1])
54+
ser = pd.Series(range(3), index=index)
55+
56+
assert ser.iloc._is_scalar_access((1,))
57+
58+
df = ser.to_frame()
59+
assert df.iloc._is_scalar_access((1, 0,))
60+
5061
def test_iloc_exceeds_bounds(self):
5162

5263
# GH6296

0 commit comments

Comments
 (0)