@@ -753,16 +753,20 @@ def group_sum(
753
753
754
754
if uses_mask:
755
755
isna_entry = mask[i, j]
756
- isna_result = result_mask[lab, j]
757
756
else :
758
757
isna_entry = _treat_as_na(val, is_datetimelike)
759
- isna_result = _treat_as_na(sumx[lab, j], is_datetimelike)
760
758
761
- if not skipna and isna_result:
762
- # If sum is already NA, don't add to it. This is important for
763
- # datetimelikebecause adding a value to NPY_NAT may not result
764
- # in a NPY_NAT
765
- continue
759
+ if not skipna:
760
+ if uses_mask:
761
+ isna_result = result_mask[lab, j]
762
+ else :
763
+ isna_result = _treat_as_na(sumx[lab, j], is_datetimelike)
764
+
765
+ if isna_result:
766
+ # If sum is already NA, don't add to it. This is important for
767
+ # datetimelikebecause adding a value to NPY_NAT may not result
768
+ # in a NPY_NAT
769
+ continue
766
770
767
771
if not isna_entry:
768
772
nobs[lab, j] += 1
@@ -845,14 +849,18 @@ def group_prod(
845
849
846
850
if uses_mask:
847
851
isna_entry = mask[i, j]
848
- isna_result = result_mask[lab, j]
849
852
else :
850
853
isna_entry = _treat_as_na(val, False )
851
- isna_result = _treat_as_na(prodx[lab, j], False )
852
854
853
- if not skipna and isna_result:
854
- # If prod is already NA, no need to update it
855
- continue
855
+ if not skipna:
856
+ if uses_mask:
857
+ isna_result = result_mask[lab, j]
858
+ else :
859
+ isna_result = _treat_as_na(prodx[lab, j], False )
860
+
861
+ if isna_result:
862
+ # If prod is already NA, no need to update it
863
+ continue
856
864
857
865
if not isna_entry:
858
866
nobs[lab, j] += 1
@@ -919,22 +927,30 @@ def group_var(
919
927
920
928
if uses_mask:
921
929
isna_entry = mask[i, j]
922
- isna_result = result_mask[lab, j]
923
930
elif is_datetimelike:
924
931
# With group_var, we cannot just use _treat_as_na bc
925
932
# datetimelike dtypes get cast to float64 instead of
926
933
# to int64.
927
934
isna_entry = val == NPY_NAT
928
- isna_result = out[lab, j] == NPY_NAT
929
935
else :
930
936
isna_entry = _treat_as_na(val, is_datetimelike)
931
- isna_result = _treat_as_na(out[lab, j], is_datetimelike)
932
937
933
- if not skipna and isna_result:
934
- # If aggregate is already NA, don't add to it. This is important for
935
- # datetimelike because adding a value to NPY_NAT may not result
936
- # in a NPY_NAT
937
- continue
938
+ if not skipna:
939
+ if uses_mask:
940
+ isna_result = result_mask[lab, j]
941
+ elif is_datetimelike:
942
+ # With group_var, we cannot just use _treat_as_na bc
943
+ # datetimelike dtypes get cast to float64 instead of
944
+ # to int64.
945
+ isna_result = out[lab, j] == NPY_NAT
946
+ else :
947
+ isna_result = _treat_as_na(out[lab, j], is_datetimelike)
948
+
949
+ if isna_result:
950
+ # If aggregate is already NA, don't add to it. This is
951
+ # important for datetimelike because adding a value to NPY_NAT
952
+ # may not result in a NPY_NAT
953
+ continue
938
954
939
955
if not isna_entry:
940
956
nobs[lab, j] += 1
@@ -1232,22 +1248,30 @@ def group_mean(
1232
1248
1233
1249
if uses_mask:
1234
1250
isna_entry = mask[i, j]
1235
- isna_result = result_mask[lab, j]
1236
1251
elif is_datetimelike:
1237
1252
# With group_mean, we cannot just use _treat_as_na bc
1238
1253
# datetimelike dtypes get cast to float64 instead of
1239
1254
# to int64.
1240
1255
isna_entry = val == NPY_NAT
1241
- isna_result = sumx[lab, j] == NPY_NAT
1242
1256
else :
1243
1257
isna_entry = _treat_as_na(val, is_datetimelike)
1244
- isna_result = _treat_as_na(sumx[lab, j], is_datetimelike)
1245
1258
1246
- if not skipna and isna_result:
1247
- # If sum is already NA, don't add to it. This is important for
1248
- # datetimelike because adding a value to NPY_NAT may not result
1249
- # in NPY_NAT
1250
- continue
1259
+ if not skipna:
1260
+ if uses_mask:
1261
+ isna_result = result_mask[lab, j]
1262
+ elif is_datetimelike:
1263
+ # With group_mean, we cannot just use _treat_as_na bc
1264
+ # datetimelike dtypes get cast to float64 instead of
1265
+ # to int64.
1266
+ isna_result = sumx[lab, j] == NPY_NAT
1267
+ else :
1268
+ isna_result = _treat_as_na(sumx[lab, j], is_datetimelike)
1269
+
1270
+ if isna_result:
1271
+ # If sum is already NA, don't add to it. This is important for
1272
+ # datetimelike because adding a value to NPY_NAT may not result
1273
+ # in NPY_NAT
1274
+ continue
1251
1275
1252
1276
if not isna_entry:
1253
1277
nobs[lab, j] += 1
@@ -1909,15 +1933,20 @@ cdef group_min_max(
1909
1933
1910
1934
if uses_mask:
1911
1935
isna_entry = mask[i, j]
1912
- isna_result = result_mask[lab, j]
1913
1936
else :
1914
1937
isna_entry = _treat_as_na(val, is_datetimelike)
1915
- isna_result = _treat_as_na(group_min_or_max[lab, j],
1916
- is_datetimelike)
1917
1938
1918
- if not skipna and isna_result:
1919
- # If current min/max is already NA, it will always be NA
1920
- continue
1939
+ if not skipna:
1940
+ if uses_mask:
1941
+ isna_result = result_mask[lab, j]
1942
+ else :
1943
+ isna_result = _treat_as_na(
1944
+ group_min_or_max[lab, j], is_datetimelike
1945
+ )
1946
+
1947
+ if isna_result:
1948
+ # If current min/max is already NA, it will always be NA
1949
+ continue
1921
1950
1922
1951
if not isna_entry:
1923
1952
nobs[lab, j] += 1
0 commit comments