Skip to content
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

PERF: groupby.any/all with object dtype #50623

Merged
merged 3 commits into from Jan 7, 2023

Conversation

lukemanley
Copy link
Member

from asv_bench.benchmarks.groupby import GroupByMethods

params = dict(dtype="object", method="all", application="direct", ncols=1) 

b = GroupByMethods()
b.setup(**params)

%timeit b.time_dtype_as_field(**params)

# 881 µs ± 20.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)  -> main
# 216 µs ± 1.15 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)  -> PR

@lukemanley lukemanley added Groupby Performance Memory or execution speed performance labels Jan 7, 2023

vals = cast(np.ndarray, vals)
vals = vals.copy()
vals[isna(vals)] = True
Copy link
Member

@phofl phofl Jan 7, 2023

Choose a reason for hiding this comment

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

Can you add a comment that we will re-compute a mask later on? Hard to follow why setting = True is valid if you don't know that.

Additionally, would it be faster to check if isna(vale).any() before making a copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment and skipped the copy when possible. Seems to save a bit more more (~5%).

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -752,6 +752,7 @@ Removal of prior version deprecations/changes
Performance improvements
~~~~~~~~~~~~~~~~~~~~~~~~
- Performance improvement in :meth:`.DataFrameGroupBy.median` and :meth:`.SeriesGroupBy.median` and :meth:`.GroupBy.cumprod` for nullable dtypes (:issue:`37493`)
- Performance improvement in :meth:`.DataFrameGroupBy.all`, :meth:`.DataFrameGroupBy.any`, :meth:`.SeriesGroupBy.all`, and :meth:`.SeriesGroupBy.any` for object dtype (:issue:`#####`)
Copy link
Member

Choose a reason for hiding this comment

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

Can use PR # here assuming there is no issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, thx

@phofl phofl merged commit f4136c0 into pandas-dev:main Jan 7, 2023
@phofl
Copy link
Member

phofl commented Jan 7, 2023

Thx @lukemanley

@lukemanley lukemanley deleted the groupby-bool-agg branch January 19, 2023 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants