You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@numba.guvectorize([(numba.float64[:], numba.float64[:], numba.float64[:], numba.float64[:])], '(n),(n),(n)->(n)', nopython=True)
def g(x,y,z, res):
for i in range(x.shape[0]):
res[i]=x[i]+y[i]+z[i]
## Try for 3 inputs
df.with_columns(zz=g(pl.col('a'), pl.col('b'), pl.col('c')))
## Fails with ComputeError
## ComputeError: custom python function failed: g() takes from 3 to 4 positional arguments but 2 were given
Issue description
The docs for ufunc support don't mention anything about being limited to 2 inputs. I'm not sure if this is a bug or just an undocumented, but known, limitation.
Of course, I'd like it if it just did the same thing as going through a struct/map/lambda but if there's a underlying reason it can't be then the ufunc docs should probably updated.
It only works for 2 expression inputs indeed, because it ends up calling a reduce function, i.e. works as an accumulator. So using more than 2 expressions means it will take the first two, try to compute a result (fails if you expect three inputs), then take the result and the 3rd item, reduce again, etc.
If any Rust expert willing to pick up, the code ends up calling reduce_exprs in horizontal.rs. Doesn't seem too hard to create a similar function in which to call the function with all arguments at once.
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
Now try 3
Issue description
The docs for ufunc support don't mention anything about being limited to 2 inputs. I'm not sure if this is a bug or just an undocumented, but known, limitation.
Expected behavior
I know I can do this, which works well enough.
Of course, I'd like it if it just did the same thing as going through a struct/map/lambda but if there's a underlying reason it can't be then the ufunc docs should probably updated.
Installed versions
The text was updated successfully, but these errors were encountered: