diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index c57f64e306199..1cbfcff5e94f1 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -369,7 +369,7 @@ def _indexed_output_to_ndframe( def _wrap_applied_output( self, data: Series, - values: list[Any] | None, + values: list[Any], not_indexed_same: bool = False, ) -> DataFrame | Series: """ @@ -379,7 +379,7 @@ def _wrap_applied_output( ---------- data : Series Input data for groupby operation. - values : Optional[List[Any]] + values : List[Any] Applied output for each group. not_indexed_same : bool, default False Whether the applied outputs are not indexed the same as the group axes. @@ -388,9 +388,7 @@ def _wrap_applied_output( ------- DataFrame or Series """ - keys = self.grouper.group_keys_seq - - if len(keys) == 0: + if len(values) == 0: # GH #6265 return self.obj._constructor( [], @@ -1100,9 +1098,8 @@ def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame: return res_df def _wrap_applied_output(self, data, values, not_indexed_same=False): - keys = self.grouper.group_keys_seq - if len(keys) == 0: + if len(values) == 0: result = self.obj._constructor( index=self.grouper.result_index, columns=data.columns )