Skip to content

Commit 84f3ee1

Browse files
committed
BUG: Use UInt64HashTable in pd.unique
Uses UInt64HashTable to patch a uint64 overflow bug in pd.unique analogous to that seen in Series.unique (patched in pandas-devgh-14915).
1 parent 0725916 commit 84f3ee1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,6 @@ Bug Fixes
289289

290290

291291
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
292+
- Bug in ``pd.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14915`)
292293
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
293294
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`)

pandas/core/algorithms.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,10 @@ def _hashtable_algo(f, values, return_dtype=None):
913913
dtype = values.dtype
914914
if is_float_dtype(dtype):
915915
return f(htable.Float64HashTable, _ensure_float64)
916-
elif is_integer_dtype(dtype):
916+
elif is_signed_integer_dtype(dtype):
917917
return f(htable.Int64HashTable, _ensure_int64)
918+
elif is_unsigned_integer_dtype(dtype):
919+
return f(htable.UInt64HashTable, _ensure_uint64)
918920
elif is_datetime64_dtype(dtype):
919921
return_dtype = return_dtype or 'M8[ns]'
920922
return f(htable.Int64HashTable, _ensure_int64).view(return_dtype)

pandas/tests/test_algos.py

+5
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ def test_timedelta64_dtype_array_returned(self):
365365
tm.assert_numpy_array_equal(result, expected)
366366
self.assertEqual(result.dtype, expected.dtype)
367367

368+
def test_uint64_overflow(self):
369+
s = pd.Series([1, 2, 2**63, 2**63], dtype=np.uint64)
370+
exp = np.array([1, 2, 2**63], dtype=np.uint64)
371+
tm.assert_numpy_array_equal(algos.unique(s), exp)
372+
368373

369374
class TestIsin(tm.TestCase):
370375
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)