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

Add handling for string by-columns in dask-cudf groupby #10830

Merged
merged 5 commits into from
May 11, 2022

Conversation

charlesbluca
Copy link
Member

Converts string by-columns to lists when calling aggregation methods, which expect Groupby.by to be a list or tuple.

We might be able to do this conversion when initializing the groupby object, just started off with this approach as it seems like upstream Dask is pretty careful not to overwrite the original by input if it's a string.

Closes #10829

@charlesbluca charlesbluca added bug Something isn't working 3 - Ready for Review Ready for review by team dask-cudf non-breaking Non-breaking change labels May 11, 2022
@charlesbluca charlesbluca requested a review from a team as a code owner May 11, 2022 18:02
@github-actions github-actions bot added the Python Affects Python cuDF API. label May 11, 2022
python/dask_cudf/dask_cudf/groupby.py Outdated Show resolved Hide resolved
for c in self.obj.columns:
if c != self.by:
yield c

@_dask_cudf_nvtx_annotate
@_check_groupby_supported
def count(self, split_every=None, split_out=1):
return groupby_agg(
Copy link
Contributor

@bdice bdice May 11, 2022

Choose a reason for hiding this comment

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

It looks like these aggregations are still highly repetitive. Could we do this (perhaps in a follow-up PR) and reduce a few dozen lines?

# Internal helper method
def _make_groupby_agg(self, agg_name, split_every=None, split_out=1):
    return groupby_agg(
        self.obj,
        self.by,
        {c: agg_name for c in self._columns_not_in_by()},
        split_every=split_every,
        split_out=split_out,
        sep=self.sep,
        sort=self.sort,
        as_index=self.as_index,
        **self.dropna,
    )

and then call it in each function?

@_dask_cudf_nvtx_annotate
@_check_groupby_supported
def count(self, split_every=None, split_out=1):
    return self._make_groupby_agg("count", split_every, split_out)

Copy link
Contributor

Choose a reason for hiding this comment

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

This suggestion may also apply to Series groupby, so I'd do this in a later PR and keep the scope constrained here.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense to me - happy to open up a separate PR handling this 🙂

Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

All looks good aside from my suggestion to simplify/wrap the calls to groupby_agg to avoid repetition. That can be done in a later PR. This addresses the core issue so I'm approving.

@codecov
Copy link

codecov bot commented May 11, 2022

Codecov Report

Merging #10830 (d652157) into branch-22.06 (8d861ce) will decrease coverage by 0.08%.
The diff coverage is 94.98%.

@@               Coverage Diff                @@
##           branch-22.06   #10830      +/-   ##
================================================
- Coverage         86.40%   86.32%   -0.09%     
================================================
  Files               143      144       +1     
  Lines             22448    22654     +206     
================================================
+ Hits              19396    19555     +159     
- Misses             3052     3099      +47     
Impacted Files Coverage Δ
python/cudf/cudf/core/column/string.py 88.78% <ø> (-0.31%) ⬇️
python/cudf/cudf/core/frame.py 93.41% <ø> (ø)
python/cudf/cudf/core/indexed_frame.py 91.70% <ø> (ø)
python/cudf/cudf/io/__init__.py 100.00% <ø> (ø)
python/cudf/cudf/testing/testing.py 81.81% <50.00%> (+0.12%) ⬆️
python/cudf/cudf/io/parquet.py 90.83% <86.60%> (-1.87%) ⬇️
python/cudf/cudf/core/index.py 92.06% <88.88%> (-0.25%) ⬇️
python/cudf/cudf/core/scalar.py 89.01% <90.90%> (-0.31%) ⬇️
python/cudf/cudf/core/dataframe.py 93.78% <96.36%> (+0.08%) ⬆️
python/cudf/cudf/__init__.py 90.69% <100.00%> (+0.22%) ⬆️
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b204d0...d652157. Read the comment docs.

@galipremsagar galipremsagar added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels May 11, 2022
@galipremsagar
Copy link
Contributor

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 16d9a92 into rapidsai:branch-22.06 May 11, 2022
@charlesbluca charlesbluca deleted the fix-10829 branch July 19, 2022 14:26
rapids-bot bot pushed a commit that referenced this pull request Dec 2, 2022
Motivated by #10830 (comment), this PR attempts to consolidate some repetitive aspects of dask-cudf's groupby code with `_make_groupby_agg_call`, which replaces all `groupby_agg` calls made in groupby.py, which takes as input the few things that vary between calls.

Note that while this doesn't depend on #10830, it will be much easier to review once that is merged in, as I have based my work off the initial consolidation efforts that were made there.

cc @bdice

Authors:
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

Approvers:
  - Richard (Rick) Zamora (https://github.com/rjzamora)

URL: #10835
@vyasr vyasr added dask Dask issue and removed dask-cudf labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working dask Dask issue non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] dask-cudf unexpectedly drops columns in groupby
4 participants