@@ -601,6 +601,9 @@ def _transform(
601601 return result
602602
603603 def agg_series (self , obj : Series , func ):
604+ # Caller is responsible for checking ngroups != 0
605+ assert self .ngroups != 0
606+
604607 if is_extension_array_dtype (obj .dtype ) and obj .dtype .kind != "M" :
605608 # _aggregate_series_fast would raise TypeError when
606609 # calling libreduction.Slider
@@ -626,8 +629,10 @@ def agg_series(self, obj: Series, func):
626629 return self ._aggregate_series_pure_python (obj , func )
627630
628631 def _aggregate_series_fast (self , obj , func ):
629- # At this point we have already checked that obj.index is not a MultiIndex
630- # and that obj is backed by an ndarray, not ExtensionArray
632+ # At this point we have already checked that
633+ # - obj.index is not a MultiIndex
634+ # - obj is backed by an ndarray, not ExtensionArray
635+ # - ngroups != 0
631636 func = self ._is_builtin_func (func )
632637
633638 group_index , _ , ngroups = self .group_info
@@ -660,11 +665,9 @@ def _aggregate_series_pure_python(self, obj, func):
660665 counts [label ] = group .shape [0 ]
661666 result [label ] = res
662667
663- if result is not None :
664- # if splitter is empty, result can be None, in which case
665- # maybe_convert_objects would raise TypeError
666- result = lib .maybe_convert_objects (result , try_float = 0 )
667- # TODO: try_cast back to EA?
668+ assert result is not None
669+ result = lib .maybe_convert_objects (result , try_float = 0 )
670+ # TODO: try_cast back to EA?
668671
669672 return result , counts
670673
@@ -815,6 +818,9 @@ def groupings(self):
815818 ]
816819
817820 def agg_series (self , obj : Series , func ):
821+ # Caller is responsible for checking ngroups != 0
822+ assert self .ngroups != 0
823+
818824 if is_extension_array_dtype (obj .dtype ):
819825 # pre-empty SeriesBinGrouper from raising TypeError
820826 # TODO: watch out, this can return None
0 commit comments