Skip to content

Commit 5f4d12c

Browse files
committed
Fix group_sum NaN comparison warnings
1 parent b983366 commit 5f4d12c

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pandas/_libs/groupby.pyx

+9-11
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def group_sum(
712712
int64_t[:, ::1] nobs
713713
Py_ssize_t len_values = len(values), len_labels = len(labels)
714714
bint uses_mask = mask is not None
715-
bint isna_entry
715+
bint isna_entry, isna_result
716716

717717
if len_values != len_labels:
718718
raise ValueError("len(index) != len(labels)")
@@ -744,20 +744,18 @@ def group_sum(
744744
for j in range(K):
745745
val = values[i, j]
746746

747-
if not skipna and (
748-
(uses_mask and result_mask[lab, j]) or
749-
(is_datetimelike and sumx[lab, j] == NPY_NAT) or
750-
_treat_as_na(sumx[lab, j], False)
751-
):
752-
# If sum is already NA, don't add to it. This is important for
753-
# datetimelikebecause adding a value to NPY_NAT may not result
754-
# in a NPY_NAT
755-
continue
756-
757747
if uses_mask:
758748
isna_entry = mask[i, j]
749+
isna_result = result_mask[lab, j]
759750
else:
760751
isna_entry = _treat_as_na(val, is_datetimelike)
752+
isna_result = _treat_as_na(sumx[lab, j], is_datetimelike)
753+
754+
if not skipna and isna_result:
755+
# If sum is already NA, don't add to it. This is important for
756+
# datetimelikebecause adding a value to NPY_NAT may not result
757+
# in a NPY_NAT
758+
continue
761759

762760
if not isna_entry:
763761
nobs[lab, j] += 1

0 commit comments

Comments
 (0)