deanm0000 opened a new issue, #39954:
URL: https://github.com/apache/arrow/issues/39954
### Describe the enhancement requested
Numpy ufuncs, if given an input which has a method `__array_ufunc__` will
run that method instead of itself. I'd like to see pyarrow compute functions
have something similar.
During this step:
https://github.com/apache/arrow/blob/de53aac762fc703148f5822ed170b462a6b467d8/python/pyarrow/compute.py#L120-L131
The wrapper could be wrapped by something like this:
```
def check_for_dunder(func):
def inner_func(*args, __func=func, **kwargs):
for arg in args:
if hasattr(arg, "__pyarrow_compute__"):
return getattr(arg, "__pyarrow_compute__")(__func, *args,
**kwargs)
else:
return(__func(*args, **kwargs))
return inner_func
```
Then the upshot is that libraries like polars or others could have their
classes add a `__pyarrow_func__` method so that pyarrow compute methods are
portable. Here's an example using polars (for the example I'm writing this as a
monkey patch but the idea is that it would be in the actual polars class
definition)
```
import polars as pl
def __pc(self, func, *x):
return pl.from_arrow(func(x[0].to_arrow()))
pl.Series.__pyarrow_compute__=__pc
```
With those two pieces together, users could do:
```
s=pl.Series([1,2,3])
pc.cumulative_sum(s)
```
This could be adopted by any class and any library so that it internalizes
the code to convert data types. It isn't just specific to polars
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]