Skip to content

BUG: Ensure that scalar binops prioritize __array_ufunc__ #27117

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

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

seberg
Copy link
Member

@seberg seberg commented Aug 6, 2024

If array-ufunc is implemented, we must call always use it for all operators (that seems to be the promise).

If array_function is defined we are in the clear w.r.t. recursion because the object is either an array (can be unpacked, but already checked earlier now also), or it cannot call the ufunc without unpacking itself (otherwise it would cause recursion).

There is an oddity about __array_wrap__. Rather than trying to do odd things to deal with it, I added a comment explaining why it doens't matter (roughly: don't use our scalar priority if you want to be sure to get a chance).

If array-ufunc is implemented, we must call always use it for all
operators (that seems to be the promise).

If __array_function__ is defined we are in the clear w.r.t. recursion
because the object is either an array (can be unpacked, but already
checked earlier now also), or it cannot call the ufunc without unpacking
itself (otherwise it would cause recursion).

There is an oddity about `__array_wrap__`.  Rather than trying to
do odd things to deal with it, I added a comment explaining why it
doens't matter (roughly: don't use our scalar priority if you want
to be sure to get a chance).
@lysnikolaou
Copy link
Member

FWIW this PR fixes some (all?) of the pandas failures we've been seeing lately. I didn't run the whole test suite, since it's too slow.

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
@charris charris merged commit d602196 into numpy:main Aug 7, 2024
66 checks passed
@charris
Copy link
Member

charris commented Aug 7, 2024

Thanks Sebastian.

@seberg seberg deleted the binop-fixup branch August 7, 2024 12:55
@lysnikolaou
Copy link
Member

Can we please trigger a nightlies rebuild so that pandas CI gets happier again?

@seberg
Copy link
Member Author

seberg commented Aug 7, 2024

Can we please trigger a nightlies rebuild so that pandas CI gets happier again?

done, should take 30 minutes at most.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants