Skip to content

Commit 06141c0

Browse files
committed
REF: No need to delegate to index check of whether an int is an int
1 parent 27ebb3e commit 06141c0

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

doc/source/whatsnew/v0.23.4.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Bug Fixes
3232

3333
- Bug where calling :func:`DataFrameGroupBy.agg` with a list of functions including ``ohlc`` as the non-initial element would raise a ``ValueError`` (:issue:`21716`)
3434
- Bug in ``roll_quantile`` caused a memory leak when calling ``.rolling(...).quantile(q)`` with ``q`` in (0,1) (:issue:`21965`)
35+
- Passing a non-int scalar to ``.iloc`` now raises a more appropriate error message (:issue:`21982`)
3536
-
3637

3738
**Conversion**

pandas/core/indexing.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,25 @@ def _getitem_scalar(self, key):
21242124
return values
21252125

21262126
def _validate_integer(self, key, axis):
2127-
# return a boolean if we have a valid integer indexer
2127+
"""
2128+
Check that 'key' is a valid position in the desired axis.
2129+
2130+
Parameters
2131+
----------
2132+
key : int
2133+
Requested position
2134+
axis : int
2135+
Desired axis
2136+
2137+
Returns
2138+
-------
2139+
None
2140+
2141+
Raises
2142+
------
2143+
IndexError
2144+
If 'key' is not a valid position in axis 'axis'
2145+
"""
21282146

21292147
ax = self.obj._get_axis(axis)
21302148
l = len(ax)
@@ -2215,8 +2233,6 @@ def _getitem_axis(self, key, axis=None):
22152233

22162234
# a single integer
22172235
else:
2218-
key = self._convert_scalar_indexer(key, axis)
2219-
22202236
if not is_integer(key):
22212237
raise TypeError("Cannot index by location index with a "
22222238
"non-integer key")

pandas/tests/indexing/test_floats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_scalar_error(self):
5050
def f():
5151
s.iloc[3.0]
5252
tm.assert_raises_regex(TypeError,
53-
'cannot do positional indexing',
53+
'Cannot index by location index',
5454
f)
5555

5656
def f():

0 commit comments

Comments
 (0)