File tree 2 files changed +12
-4
lines changed 2 files changed +12
-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" ,)
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
@@ -1898,7 +1898,12 @@ def groupby_reduce(
1898
1898
min_count = 1
1899
1899
1900
1900
# TODO: set in xarray?
1901
- if min_count is not None and func in ["nansum" , "nanprod" ] and fill_value is None :
1901
+ if (
1902
+ min_count is not None
1903
+ and min_count > 0
1904
+ and func in ["nansum" , "nanprod" ]
1905
+ and fill_value is None
1906
+ ):
1902
1907
# nansum, nanprod have fill_value=0, 1
1903
1908
# overwrite than when min_count is set
1904
1909
fill_value = np .nan
You can’t perform that action at this time.
0 commit comments