Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: out=None is not propagated for overriden ufuncs #31030

@roytsmart

Description

@roytsmart

Describe the issue:

Numpy has started emitting a warning: UserWarning: 'where' used without 'out', expect unitialized memory in output. If this is intentional, use out=None.

I was trying to fix this warning in my named-arrays package which uses the __array_ufunc__() to override ufuncs, but explicitly setting out=None was ignored by the dispatch mechanism.

I'm happy to open a PR to fix the issue if someone can point me to the relevant section of code.

Reproduce the code example:

import dataclasses
import numpy as np

@dataclasses.dataclass
class DuckArray:
  ndarray: np.ndarray

  def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
    print(f"{kwargs=}")
    return ufunc(
        *[x.ndarray if isinstance(x, DuckArray) else x for x in inputs],
        **kwargs,
    )

a = DuckArray(1)

np.log(a, where=True, out=None,)

Error message:

kwargs={'where': True}
/tmp/ipykernel_7190/684948999.py:10: UserWarning: 'where' used without 'out', expect unitialized memory in output. If this is intentional, use out=None.
  return ufunc(
np.float64(0.0)

Python and NumPy Versions:

2.4.3
3.12.13 (main, Mar 4 2026, 09:23:07) [GCC 11.4.0]

Runtime Environment:

[{'numpy_version': '2.4.3',
'python': '3.12.13 (main, Mar 4 2026, 09:23:07) [GCC 11.4.0]',
'uname': uname_result(system='Linux', node='6a2ba07866f2', release='6.6.113+', version='#1 SMP Mon Feb 2 12:27:57 UTC 2026', machine='x86_64')},
{'simd_extensions': {'baseline': ['X86_V2'],
'found': ['X86_V3'],
'not_found': ['X86_V4', 'AVX512_ICL', 'AVX512_SPR']}},
{'ignore_floating_point_errors_in_matmul': False},
{'architecture': 'Haswell',
'filepath': '/usr/local/lib/python3.12/dist-packages/numpy.libs/libscipy_openblas64_-ff84a88b.so',
'internal_api': 'openblas',
'num_threads': 2,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.31.dev'}]

How does this issue affect you or how did you find it:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions