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

[FEA] Support passing arguments to functions in groupby apply #10295

Closed
beckernick opened this issue Feb 15, 2022 · 1 comment · Fixed by #10682
Closed

[FEA] Support passing arguments to functions in groupby apply #10295

beckernick opened this issue Feb 15, 2022 · 1 comment · Fixed by #10682
Labels
dask Dask issue feature request New feature or request Python Affects Python cuDF API.

Comments

@beckernick
Copy link
Member

In pandas , I can pass arguments to a function used with groupby.apply. This is currently used internally to the Dask codebase (#10294) and also exposed in the public interface.

import dask.dataframe as dd
import pandas as pd
import dask_cudf
import cudfdf = pd.DataFrame({
    "a": [0,0,1,0,0,1,1,1,1,1],
    "b": [0,0.3,0,-4,0,-3,1,1,11,1],
    "c": [19,0,30,0,0,1,41,1,1,1],
})
gdf = cudf.from_pandas(df)
ddf = dd.from_pandas(df, 2)
gddf = dask_cudf.from_dask_dataframe(ddf)
​
def func(x, delta):
    return x + deltaprint(df.groupby("a").b.apply(func, 3))
print(ddf.groupby("a").b.apply(func, 3).compute())
0     3.0
1     3.3
2     3.0
3    -1.0
4     3.0
5     0.0
6     4.0
7     4.0
8    14.0
9     4.0
Name: b, dtype: float64
2     3.0
5     0.0
6     4.0
7     4.0
8    14.0
9     4.0
0     3.0
1     3.3
3    -1.0
4     3.0
Name: b, dtype: float64
/tmp/ipykernel_78541/1691277680.py:19: UserWarning: `meta` is not specified, inferred from partial data. Please provide `meta` if the result is unexpected.
  Before: .apply(func)
  After:  .apply(func, meta={'x': 'f8', 'y': 'f8'}) for dataframe result
  or:     .apply(func, meta=('x', 'f8'))            for series result
  print(ddf.groupby("a").b.apply(func, 3).compute())
@beckernick beckernick added feature request New feature or request Python Affects Python cuDF API. dask Dask issue labels Feb 15, 2022
@github-actions
Copy link

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dask Dask issue feature request New feature or request Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant