Skip to content

BUG: Ensure that scalar binops prioritize __array_ufunc__ - #27117

Merged
charris merged 2 commits into
numpy:mainfrom
seberg:binop-fixup
Aug 7, 2024
Merged

charris merged 2 commits into
numpy:mainfrom
seberg:binop-fixup

Conversation

@seberg

@seberg seberg commented Aug 6, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

Comment thread numpy/_core/tests/test_multiarray.py Resolved
@charris
charris merged commit d602196 into numpy:main Aug 7, 2024
@charris

charris commented Aug 7, 2024

Copy link
Copy Markdown
Member

Thanks Sebastian.

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

Copy link
Copy Markdown
Member

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

@seberg

seberg commented Aug 7, 2024 •

Copy link
Copy Markdown
Member Author

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