Skip to content

REF: Groupby length checks on values instead of keys #43490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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.
Expand All @@ -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(
[],
Expand Down Expand Up @@ -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
)
Expand Down