From 804feea1e88c77a8793561c3bc7a1186ba474267 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 18 Feb 2020 16:06:34 -0800 Subject: [PATCH 1/2] Fix incorrect _is_scalar_access check in iloc --- pandas/core/generic.py | 4 ++-- pandas/core/indexing.py | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 579daae2b15c6..ac03843a0e27d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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): diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index d3e75d43c6bd7..c366b0621fe93 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -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: From 7f89d7671703c9f1f1d5080eed8d23480bb425cd Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 19 Feb 2020 17:21:27 -0800 Subject: [PATCH 2/2] add test --- pandas/tests/indexing/test_iloc.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index 500bd1853e9a4..683d4f2605712 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -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