File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -557,12 +557,15 @@ def _initialize_aggregation(
557
557
assert isinstance (finalize_kwargs , dict )
558
558
agg .finalize_kwargs = finalize_kwargs
559
559
560
+ if min_count is None :
561
+ min_count = 0
562
+
560
563
# This is needed for the dask pathway.
561
564
# Because we use intermediate fill_value since a group could be
562
565
# absent in one block, but present in another block
563
566
# We set it for numpy to get nansum, nanprod tests to pass
564
567
# where the identity element is 0, 1
565
- if min_count is not None :
568
+ if min_count > 0 :
566
569
agg .min_count = min_count
567
570
agg .chunk += ("nanlen" ,)
568
571
agg .numpy += ("nanlen" ,)
@@ -571,5 +574,7 @@ def _initialize_aggregation(
571
574
agg .fill_value ["numpy" ] += (0 ,)
572
575
agg .dtype ["intermediate" ] += (np .intp ,)
573
576
agg .dtype ["numpy" ] += (np .intp ,)
577
+ else :
578
+ agg .min_count = 0
574
579
575
580
return agg
Original file line number Diff line number Diff line change @@ -849,7 +849,7 @@ def _finalize_results(
849
849
"""
850
850
squeezed = _squeeze_results (results , axis )
851
851
852
- if agg .min_count is not None :
852
+ if agg .min_count > 0 :
853
853
counts = squeezed ["intermediates" ][- 1 ]
854
854
squeezed ["intermediates" ] = squeezed ["intermediates" ][:- 1 ]
855
855
@@ -860,7 +860,7 @@ def _finalize_results(
860
860
else :
861
861
finalized [agg .name ] = agg .finalize (* squeezed ["intermediates" ], ** agg .finalize_kwargs )
862
862
863
- if agg .min_count is not None :
863
+ if agg .min_count > 0 :
864
864
count_mask = counts < agg .min_count
865
865
if count_mask .any ():
866
866
# For one count_mask.any() prevents promoting bool to dtype(fill_value) unless
@@ -1917,7 +1917,12 @@ def groupby_reduce(
1917
1917
min_count = 1
1918
1918
1919
1919
# TODO: set in xarray?
1920
- if min_count is not None and func in ["nansum" , "nanprod" ] and fill_value is None :
1920
+ if (
1921
+ min_count is not None
1922
+ and min_count > 0
1923
+ and func in ["nansum" , "nanprod" ]
1924
+ and fill_value is None
1925
+ ):
1921
1926
# nansum, nanprod have fill_value=0, 1
1922
1927
# overwrite than when min_count is set
1923
1928
fill_value = np .nan
You can’t perform that action at this time.
0 commit comments