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

Enable column projection for groupby slicing #9667

Merged
merged 6 commits into from Nov 30, 2022

Conversation

rjzamora
Copy link
Member

@rjzamora rjzamora commented Nov 16, 2022

After #9442, dask will insert a getitem operation to enable column projection for operations like groupby().agg. As pointed out in this external commit, dask does not yet capture a simple groupby().[<slice>] case.

This PR simply adds a getitem operation for groupby slicing.

  • Closes #xxxx
  • Tests added / passed
  • Passes pre-commit run --all-files

@rjzamora rjzamora added dataframe highlevelgraph Issues relating to HighLevelGraphs. labels Nov 16, 2022
rjzamora referenced this pull request in EthanRosenthal/medium-data-bakeoff Nov 16, 2022

# Check if we can project columns
projection = None
if isinstance(self._slice, (str, list)):
Copy link
Member

Choose a reason for hiding this comment

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

What other types are valid here?

EDIT: Aside from None, given that this is an optional kwarg

Copy link
Member Author

Choose a reason for hiding this comment

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

The slice= kwarg is set by the key in a DataFrameGroupBy.__getitem__ call. Therefore, I suppose it can be anything representing a column selection. I opted to keep the projection simple here for now, but we certainly can generalize this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully the latest code supports all (reasonable) self._slice types (numpy scalar, str, list, tuple, index-like, and series-like)

Copy link
Member

@fjetter fjetter left a comment

Choose a reason for hiding this comment

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

I think tuples are just as common as lists. We're also handling this for by.

If we include these suggestions, I'm +1 for merging. I think this is a really nice improvement! Thanks @rjzamora

dask/dataframe/tests/test_groupby.py Outdated Show resolved Hide resolved
dask/dataframe/groupby.py Outdated Show resolved Hide resolved
Copy link
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks @rjzamora for the improvement and @fjetter for reviewing

@jrbourbeau jrbourbeau merged commit 49b516b into dask:main Nov 30, 2022
@rjzamora rjzamora deleted the groupby-slice-projection branch November 30, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dataframe highlevelgraph Issues relating to HighLevelGraphs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants