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

Add __array_function__ to dispatch NumPy funcs to dask-awkward #520

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/dask_awkward/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,57 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
**kwargs,
)

def __array_function__(self, func, types, args, kwargs):
import dask_awkward as dak

# List of supported functions
supported_funcs = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mildly prefer this as a global constant rather than in the function

"amin": dak.amin,
"nanmin": dak.nanmin,
"count_nonzero": dak.count_nonzero,
"mean": dak.mean,
"nanmean": dak.nanmean,
"concatenate": dak.concatenate,
"sum": dak.sum,
"nansum": dak.nansum,
"argsort": dak.argsort,
"copy": dak.copy,
"nan_to_num": dak.nan_to_num,
"ones_like": dak.ones_like,
"zeros_like": dak.zeros_like,
"prod": dak.prod,
"nanprod": dak.nanprod,
"sort": dak.sort,
"var": dak.var,
"nanvar": dak.nanvar,
"round": dak.round,
"ptp": dak.ptp,
"any": dak.any,
"imag": dak.imag,
"real": dak.real,
"broadcast_arrays": dak.broadcast_arrays,
"std": dak.std,
"nanstd": dak.nanstd,
"isclose": dak.isclose,
"full_like": dak.full_like,
"all": dak.all,
"amax": dak.amax,
"nanmax": dak.nanmax,
"argmax": dak.argmax,
"nanargmax": dak.nanargmax,
"where": dak.where,
"angle": dak.angle,
"ravel": dak.ravel,
"argmin": dak.argmin,
"nanargmin": dak.nanargmin,
}

# Check if the function is supported
if func.__name__ in supported_funcs:
return supported_funcs[func.__name__](*args, **kwargs)
else:
return NotImplemented
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return NotImplemented
return NotImplemented(str(func))


def __array__(self, *_, **__):
raise NotImplementedError

Expand Down