diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index af1bee435eead..940505c01d6c6 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1254,6 +1254,7 @@ Indexing - Bug in ``.loc`` assignment with a single-element list-like incorrectly assigns as a list (:issue:`19474`) - Bug in partial string indexing on a ``Series/DataFrame`` with a monotonic decreasing ``DatetimeIndex`` (:issue:`19362`) - Bug in :meth:`IntervalIndex.get_loc` and :meth:`IntervalIndex.get_indexer` when used with an :class:`IntervalIndex` containing a single interval (:issue:`17284`, :issue:`20921`) +- Bug in ``.loc`` with a ``uint64`` indexer (:issue:`20722`) MultiIndex ^^^^^^^^^^ diff --git a/pandas/_libs/khash.pxd b/pandas/_libs/khash.pxd index b1d965c3618cd..4c00e273b33b7 100644 --- a/pandas/_libs/khash.pxd +++ b/pandas/_libs/khash.pxd @@ -84,9 +84,9 @@ cdef extern from "khash_python.h": kh_uint64_t* kh_init_uint64() nogil void kh_destroy_uint64(kh_uint64_t*) nogil void kh_clear_uint64(kh_uint64_t*) nogil - khint_t kh_get_uint64(kh_uint64_t*, int64_t) nogil + khint_t kh_get_uint64(kh_uint64_t*, uint64_t) nogil void kh_resize_uint64(kh_uint64_t*, khint_t) nogil - khint_t kh_put_uint64(kh_uint64_t*, int64_t, int*) nogil + khint_t kh_put_uint64(kh_uint64_t*, uint64_t, int*) nogil void kh_del_uint64(kh_uint64_t*, khint_t) nogil bint kh_exist_uint64(kh_uint64_t*, khiter_t) nogil diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 6ccff7e898a6a..2e52154d7679b 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -784,3 +784,22 @@ def convert_nested_indexer(indexer_type, keys): index=pd.MultiIndex.from_product(keys)) tm.assert_series_equal(result, expected) + + def test_loc_uint64(self): + # GH20722 + # Test whether loc accept uint64 max value as index. + s = pd.Series([1, 2], + index=[np.iinfo('uint64').max - 1, + np.iinfo('uint64').max]) + + result = s.loc[np.iinfo('uint64').max - 1] + expected = s.iloc[0] + assert result == expected + + result = s.loc[[np.iinfo('uint64').max - 1]] + expected = s.iloc[[0]] + tm.assert_series_equal(result, expected) + + result = s.loc[[np.iinfo('uint64').max - 1, + np.iinfo('uint64').max]] + tm.assert_series_equal(result, s)