-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
ComputeError when applying an UDF in a group_by
aggregation
#13557
Comments
It's because of #13181. If you do...
then it works. One quick note on background. When you use a ufunc, polars recognizes it and automatically runs it through The issue is that To fix that behavior @ritchie46 added a parameter to Maybe there's a way to make this chunk a bit smarter: polars/py-polars/polars/expr/expr.py Lines 265 to 284 in f8762fb
One idea is to check the |
Thanks a lot for suggesting this fix. To me the current state seems a bit unintuitive, i.e. import polars as pl
def expm1(values: pl.Expr) -> pl.Expr:
return values.exp() - 1.0
if __name__ == "__main__":
frame = pl.from_dict({"id": ["a", "a", "b", "b"], "values": [0.1, 0.1, -0.1, -0.1]})
frame.group_by(by="id").agg(pl.col("values").log1p().sum().pipe(expm1)) is working perfectly fine, but with an unstable implmentation of This means I cannot simply use a Having the ability to substitute a 'ufunc' for an expression is a great thing since In that light I am thinking about reopening #12891 since having available a stable |
Turns out all the stock prebuilt ufuncs are elementwise so I made a PR to change how they're dispatched to using that flag. |
Checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Reproducible example
Log output
No response
Issue description
The same expression was working in
polars-0.19.19
.Expected behavior
Should apply the UDF to the 'sum', no exception should be raised.
Installed versions
The text was updated successfully, but these errors were encountered: