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
As in the above, when calling a guvectorised ufunc expression (here declared with numba) and applying a .over() condition polars produces unexpected results by passing in all inputs to the ufunc as if it had not been constrained by the over.
I expect the output to be equivalent in both cases, and for the keep_between function to be called twice in the first instance, but only once in the second instance. Instead, I see that the function is called as if .over was not included in transform:
The way ufuncs work, in the general case, is that when any of their inputs are a class that has an __array_ufunc__ method then it will run that method. Polars makes ufuncs work as a direct input by having such a method defined on expressions. When the ufunc runs the __array_ufunc__ method the input is just pl.col('value').
What should happen is that either numpy/python should raise because my_func doesn't have an .over method OR it should pass along the method with the rest of the arguments to the __array_ufunc__ method. If numpy implements the latter case then this could work as you're trying it.
It turns out that when we do my_func(pl.col("value")) it resolves to col('value').map_batches(my_func) which means that when you do my_func(pl.col("value")).over('category') it resolves to col('value').map_batches(my_func).over('category')
The test would need a numba dependency. I'm under the impression (perhaps mistakenly) that having numba required isn't wanted in the test suite. Even then it's probably only helpful to test that case sporadically (to catch when/if numba or numpy change) rather than for every PR.
Checks
Reproducible example
Log output
No response
Issue description
As in the above, when calling a guvectorised ufunc expression (here declared with numba) and applying a
.over()
condition polars produces unexpected results by passing in all inputs to the ufunc as if it had not been constrained by theover
.This is likely related to #14507
Expected behavior
I expect the output to be equivalent in both cases, and for the keep_between function to be called twice in the first instance, but only once in the second instance. Instead, I see that the function is called as if .over was not included in
transform
:Installed versions
The text was updated successfully, but these errors were encountered: