-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
BUG: reductions like np.sum can error on objects that handle ufuncs fine #21387
Comments
@machow removing the method path seems like a pretty big change. Do you have any idea for what NumPy could do to help you? |
@seberg thanks for you quick reply! Do you mind giving some context on what makes the change feel big? It makes sense that there's history / downstream libraries to consider, and I'd be curious to hear the important jobs this first path in wrapreduction is doing (It would be surprising for objects to need this, and also not have If |
Calling the methods is much older than |
Ah, thanks for the pointer! If it allows dispatching more numpy methods (and is the future), it seems like the way to go!
Yeah, same issue. I've noticed libraries like pandas are not using I guess if I raise an error in In any event, thanks for the context and nudge to the future :). I tested out |
Okay--just a note for posterity.. after reading through the
So if I understand correctly, siuba needs to implement both |
Describe the issue:
Hey--I'm adding support for ufuncs to siuba, which allows users to specify what they want to do, before executing on a backend (e.g. pandas, sql).
Currently, I'm able to support ufuncs (in machow/siuba#415), but noticed that some functions that ultimately call ufuncs--like np.sum--don't make it that far.
It looks like this is because calls like
np.sum(some_obj)
follow this logic:hasattr(some_obj, "sum")
? if so, use that method.np.add.reduce(some_obj, ...)
This leads to a tricky situation where
np.add.reduce
works fine, butnp.sum
raises an error (because it goes through the first path, not__array_ufunc__
).Reproduce the code example:
Below are two examples: one in siuba, and one in polars
Siuba example
Outputs siuba's abstract syntax tree (AST) for the ufunc call:
However, this code produces the wrong AST, because it does not dispatch to
__array_ufunc__
:Polars example
It looks like this also causes issues with https://github.com/pola-rs/polars (cc @ritchie46):
Error message:
Here's the full stacktrace for polars (siuba does not error, but erroneously has the
.sum()
method called, rather than__array_ufunc__
.NumPy/Python version information:
The text was updated successfully, but these errors were encountered: