diff --git a/pandas/_libs/groupby_helper.pxi.in b/pandas/_libs/groupby_helper.pxi.in index 8e351244b7f43..000689f634545 100644 --- a/pandas/_libs/groupby_helper.pxi.in +++ b/pandas/_libs/groupby_helper.pxi.in @@ -76,7 +76,11 @@ def group_last_{{name}}({{c_type}}[:, :] out, val = values[i, j] # not nan - if val == val and val != {{nan_val}}: + if ( + {{if not name.startswith("int")}} + val == val and + {{endif}} + val != {{nan_val}}): nobs[lab, j] += 1 resx[lab, j] = val @@ -133,7 +137,11 @@ def group_nth_{{name}}({{c_type}}[:, :] out, val = values[i, j] # not nan - if val == val and val != {{nan_val}}: + if ( + {{if not name.startswith("int")}} + val == val and + {{endif}} + val != {{nan_val}}): nobs[lab, j] += 1 if nobs[lab, j] == rank: resx[lab, j] = val diff --git a/pandas/_libs/hashtable_class_helper.pxi.in b/pandas/_libs/hashtable_class_helper.pxi.in index bf2189a8c1fd7..17f1d011af01b 100644 --- a/pandas/_libs/hashtable_class_helper.pxi.in +++ b/pandas/_libs/hashtable_class_helper.pxi.in @@ -424,8 +424,12 @@ cdef class {{name}}HashTable(HashTable): for i in range(n): val = values[i] - if ignore_na and (val != val - or (use_na_value and val == na_value2)): + if ignore_na and ( + {{if not name.lower().startswith(("uint", "int"))}} + val != val or + {{endif}} + (use_na_value and val == na_value2) + ): # if missing values do not count as unique values (i.e. if # ignore_na is True), skip the hashtable entry for them, # and replace the corresponding label with na_sentinel