Skip to content

PERF: grouped_reduce #43576

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 1 commit into from
Sep 15, 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
6 changes: 5 additions & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
BlockManager
"""
result_blocks: list[Block] = []
dropped_any = False

for blk in self.blocks:
if blk.is_object:
Expand All @@ -1259,6 +1260,7 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
except (TypeError, NotImplementedError):
if not ignore_failures:
raise
dropped_any = True
continue
result_blocks = extend_blocks(applied, result_blocks)
else:
Expand All @@ -1267,6 +1269,7 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
except (TypeError, NotImplementedError):
if not ignore_failures:
raise
dropped_any = True
continue
result_blocks = extend_blocks(applied, result_blocks)

Expand All @@ -1275,7 +1278,8 @@ def grouped_reduce(self: T, func: Callable, ignore_failures: bool = False) -> T:
else:
index = Index(range(result_blocks[0].values.shape[-1]))

if ignore_failures:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you kill ignore_failures now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, though we can get rid of it in 2.0 BC of the nuisance column derecations

if dropped_any:
# faster to skip _combine if we haven't dropped any blocks
return self._combine(result_blocks, copy=False, index=index)

return type(self).from_blocks(result_blocks, [self.axes[0], index])
Expand Down