From bcda21e12b1b2ba81082c26944db6a34640fb768 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 26 Jan 2020 10:39:10 -0800 Subject: [PATCH 1/3] BUG: ser.at match ser.loc with Float64Index --- pandas/core/indexing.py | 2 +- pandas/tests/indexes/test_numeric.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 4550be791b1ec..758829d486f8a 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -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 " diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index b83ceb1ce699c..be3e62698dce1 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -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") @@ -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#???? .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 From 940a72761245860e327a008dddcd29868ec303b7 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 26 Jan 2020 10:39:58 -0800 Subject: [PATCH 2/3] update GH ref --- pandas/tests/indexes/test_numeric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index be3e62698dce1..992a91ad8a528 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -425,7 +425,7 @@ def test_lookups_datetimelike_values(self, vals): result = ser.at[4.0] assert isinstance(result, type(expected)) and result == expected - # GH#???? .at[4] should cast to 4.0, matching .loc behavior + # GH#31329 .at[4] should cast to 4.0, matching .loc behavior result = ser.at[4] assert isinstance(result, type(expected)) and result == expected From f3f1a2ff062639f8564b86545907026c1bd2efbf Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 30 Jan 2020 17:08:44 -0800 Subject: [PATCH 3/3] whatsnew --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 920919755dc23..0aba9de7d0667 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -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 ^^^^^^^