Skip to content

BUG: ser.at match ser.loc with Float64Index #31329

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 5 commits into from
Jan 31, 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Indexing
^^^^^^^^
- 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`)
- Bug in :meth:`PeriodIndex.get_loc` treating higher-resolution strings differently from :meth:`PeriodIndex.get_value` (:issue:`31172`)
-
- Bug in :meth:`Series.at` and :meth:`DataFrame.at` not matching ``.loc`` behavior when looking up an integer in a :class:`Float64Index` (:issue:`31329`)

Missing
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ def _convert_key(self, key, is_setter: bool = False):
"can only have integer indexers"
)
else:
if is_integer(i) and not ax.holds_integer():
if is_integer(i) and not (ax.holds_integer() or ax.is_floating()):
raise ValueError(
"At based indexing on an non-integer "
"index can only have non-integer "
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def test_get_loc_missing_nan(self):
)
def test_lookups_datetimelike_values(self, vals):
# If we have datetime64 or timedelta64 values, make sure they are
# wrappped correctly
# wrappped correctly GH#31163
ser = pd.Series(vals, index=range(3, 6))
ser.index = ser.index.astype("float64")

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

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

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