From 68f6b90293b932915090efba95974dae9d4dad55 Mon Sep 17 00:00:00 2001 From: Licht-T Date: Sun, 6 May 2018 16:53:22 +0900 Subject: [PATCH 1/4] BUG: Fix wrong khash method definition --- pandas/_libs/khash.pxd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 0596d3e925f2ac2887db02a85f4a2b58c8a8841b Mon Sep 17 00:00:00 2001 From: Licht-T Date: Sun, 6 May 2018 16:59:29 +0900 Subject: [PATCH 2/4] TST: Add test for loc with large uint64 index --- pandas/tests/indexing/test_loc.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 6ccff7e898a6a..7b753a25513b0 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -784,3 +784,32 @@ 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 + ] + ) + exp1 = pd.Series( + [1], + index=[ + 18446744073709551614 + ] + ) + exp2 = pd.Series( + [2], + index=[ + 18446744073709551615 + ] + ) + + tm.assert_series_equal(s.loc[[np.iinfo('uint64').max - 1]], exp1) + assert 1 == s.loc[np.iinfo('uint64').max - 1] + + tm.assert_series_equal(s.loc[[np.iinfo('uint64').max]], exp2) + assert 2 == s.loc[np.iinfo('uint64').max] From 69a01a3c07683639bcf779db32059313f07346d0 Mon Sep 17 00:00:00 2001 From: Licht-T Date: Mon, 7 May 2018 22:58:23 +0900 Subject: [PATCH 3/4] DOC: Add whatsnew note --- doc/source/whatsnew/v0.23.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 979fbb5ddfdd0..b4027cca4c229 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1246,6 +1246,7 @@ Indexing - Bug in ``Series.is_unique`` where extraneous output in stderr is shown if Series contains objects with ``__ne__`` defined (:issue:`20661`) - 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 ``.loc``, which cannot handle ``uint64`` input (:issue:`20722`) MultiIndex ^^^^^^^^^^ From 375c656d1ef2667eb52d27a4a4e5fa7e72076387 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Mon, 7 May 2018 20:11:23 -0400 Subject: [PATCH 4/4] test clean --- doc/source/whatsnew/v0.23.0.txt | 2 +- pandas/tests/indexing/test_loc.py | 40 ++++++++++++------------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index b29875ff86268..940505c01d6c6 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1254,7 +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``, which cannot handle ``uint64`` input (:issue:`20722`) +- Bug in ``.loc`` with a ``uint64`` indexer (:issue:`20722`) MultiIndex ^^^^^^^^^^ diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 7b753a25513b0..2e52154d7679b 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -788,28 +788,18 @@ def convert_nested_indexer(indexer_type, keys): 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 - ] - ) - exp1 = pd.Series( - [1], - index=[ - 18446744073709551614 - ] - ) - exp2 = pd.Series( - [2], - index=[ - 18446744073709551615 - ] - ) - - tm.assert_series_equal(s.loc[[np.iinfo('uint64').max - 1]], exp1) - assert 1 == s.loc[np.iinfo('uint64').max - 1] - - tm.assert_series_equal(s.loc[[np.iinfo('uint64').max]], exp2) - assert 2 == s.loc[np.iinfo('uint64').max] + 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)