FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

BUG: Allow explicit `out=None` for `ufunc` overrides. by roytsmart · Pull Request #31032 · numpy/numpy · GitHub

/ numpy Public

BUG: Allow explicit out=None for ufunc overrides. - #31032

Open
roytsmart wants to merge 8 commits into
numpy:mainfrom
roytsmart:bugfix/explicit-out-equal-none
Open

BUG: Allow explicit out=None for ufunc overrides.#31032
roytsmart wants to merge 8 commits into
numpy:mainfrom
roytsmart:bugfix/explicit-out-equal-none

Conversation

Copy link
Copy Markdown
Contributor

PR summary

This PR fixes #31030 by not deleting out at the end of initialize_normal_kwds().

seberg commented Mar 19, 2026
edited
Loading

Copy link
Copy Markdown
Member

Hmmm, until now we explicitly protected from it, so this might break someones __array_ufunc__ implementation in theory (I haven't looked if any of the big ones -- e.g. dask/astropy/cupy would notice).

But, I can't think of a different way to ensure the warning isn't given. But we could at least make it conditional on where to (very much) reduce the potential blast radius (since where= isn't used a lot).

Can you also check if the docs need to be updated about this? And maybe add a brief release note.

EDIT: Also clearly, the tests are failing, and need to be adapted to test whatever new behavior we have.

charris changed the title Allow explicit out=None for ufunc overrides. BUG: Allow explicit out=None for ufunc overrides. Mar 19, 2026
charris added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

@ngoldbaum, do you know why the tests are failing? I thought where would be in normal_kwds, but the test failure seems to indicate that it's not, unless I'm making a silly mistake.

seberg commented Mar 19, 2026

Copy link
Copy Markdown
Member

I think the reason for the failure is that out is passed by position and not kwarg, so it is never part of the dict from the start. I dunno if it matters much, I guess you would instead have to add out=None to the kwargs (but then if there are multiple out should it be (None, None)?
(I would be tempted to pass in the info that where is passed, as it is available, but more of an opinion. Just to avoid the Contains)

Allow explicit `out=None` for `ufunc` overrides if the `where` keyword is present
---------------------------------------------------------------------------------
Numpy now emits the warning:
``UserWarning: 'where' used without 'out', expect unitialized memory in output.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unitialized ==> uninitialized, but I suppose the spelling also exists in the actual warning issued by NumPy, so maybe not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

🙃

We should probably fix that typo in the warning text too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You don't think that's appropriate to do in this PR, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You could do it here. We'll probably want to backport this and it will make that a little easier.

Copy link
Copy Markdown
Member

One thing that might also help is to debug a local build of numpy with gdb or lldb:

https://numpy.org/devdocs/dev/development_advanced_debugging.html#c-debuggers

I'll try to take a closer look to understand what's going wrong. Also ping @mattip - this is fixing some fallout from merging #29813 for projects that implement __array_ufunc__.

Copy link
Copy Markdown
Contributor Author

Thanks @ngoldbaum, I will get that set up.

I'm surprised wheremask_obj == NULL didn't work, I need to read the code further to determine how the override knows if where is passed,.

mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@roytsmart - I think the test failures actually make some sense given what the warning was trying to do, but worry this is the wrong approach, as __array_ufunc__ implementations will expect out to be a tuple. See my comment at #31030 (comment)

@@ -3663,17 +3663,17 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
res = np.multiply.reduce(a, None, out=(None,), dtype=None)
assert_equal(res[4], {'axis': None, 'dtype': None})
res = np.multiply.reduce(a, 0, None, None, False, 2, True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In this test and the ones below, both out and where are passed as positional parameters, so it seems correct that a warning would later be emitted.

But see my more general comment.

charris removed the 09 - Backport-Candidate PRs tagged should be backported label May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

BUG: out=None is not propagated for overriden ufuncs

6 participants


Back | FazBrowse Home | New Git URL