Skip to content

Commit 948f957

Browse files
authored
BUG: ser.at match ser.loc with Float64Index (#31329)
1 parent 426d445 commit 948f957

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Indexing
148148
^^^^^^^^
149149
- Bug in slicing on a :class:`DatetimeIndex` with a partial-timestamp dropping high-resolution indices near the end of a year, quarter, or month (:issue:`31064`)
150150
- Bug in :meth:`PeriodIndex.get_loc` treating higher-resolution strings differently from :meth:`PeriodIndex.get_value` (:issue:`31172`)
151-
-
151+
- Bug in :meth:`Series.at` and :meth:`DataFrame.at` not matching ``.loc`` behavior when looking up an integer in a :class:`Float64Index` (:issue:`31329`)
152152

153153
Missing
154154
^^^^^^^

pandas/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ def _convert_key(self, key, is_setter: bool = False):
21242124
"can only have integer indexers"
21252125
)
21262126
else:
2127-
if is_integer(i) and not ax.holds_integer():
2127+
if is_integer(i) and not (ax.holds_integer() or ax.is_floating()):
21282128
raise ValueError(
21292129
"At based indexing on an non-integer "
21302130
"index can only have non-integer "

pandas/tests/indexes/test_numeric.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def test_get_loc_missing_nan(self):
402402
)
403403
def test_lookups_datetimelike_values(self, vals):
404404
# If we have datetime64 or timedelta64 values, make sure they are
405-
# wrappped correctly
405+
# wrappped correctly GH#31163
406406
ser = pd.Series(vals, index=range(3, 6))
407407
ser.index = ser.index.astype("float64")
408408

@@ -425,7 +425,9 @@ def test_lookups_datetimelike_values(self, vals):
425425

426426
result = ser.at[4.0]
427427
assert isinstance(result, type(expected)) and result == expected
428-
# Note: ser.at[4] raises ValueError; TODO: should we make this match loc?
428+
# GH#31329 .at[4] should cast to 4.0, matching .loc behavior
429+
result = ser.at[4]
430+
assert isinstance(result, type(expected)) and result == expected
429431

430432
result = ser.iloc[1]
431433
assert isinstance(result, type(expected)) and result == expected

0 commit comments

Comments
 (0)