@@ -601,6 +601,9 @@ def _transform(
601
601
return result
602
602
603
603
def agg_series (self , obj : Series , func ):
604
+ # Caller is responsible for checking ngroups != 0
605
+ assert self .ngroups != 0
606
+
604
607
if is_extension_array_dtype (obj .dtype ) and obj .dtype .kind != "M" :
605
608
# _aggregate_series_fast would raise TypeError when
606
609
# calling libreduction.Slider
@@ -626,8 +629,10 @@ def agg_series(self, obj: Series, func):
626
629
return self ._aggregate_series_pure_python (obj , func )
627
630
628
631
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
631
636
func = self ._is_builtin_func (func )
632
637
633
638
group_index , _ , ngroups = self .group_info
@@ -660,11 +665,9 @@ def _aggregate_series_pure_python(self, obj, func):
660
665
counts [label ] = group .shape [0 ]
661
666
result [label ] = res
662
667
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?
668
671
669
672
return result , counts
670
673
@@ -815,6 +818,9 @@ def groupings(self):
815
818
]
816
819
817
820
def agg_series (self , obj : Series , func ):
821
+ # Caller is responsible for checking ngroups != 0
822
+ assert self .ngroups != 0
823
+
818
824
if is_extension_array_dtype (obj .dtype ):
819
825
# pre-empty SeriesBinGrouper from raising TypeError
820
826
# TODO: watch out, this can return None
0 commit comments