Skip to content

BUG: sqrt(ma.masked) returns non-masked array #25635

@crusaderky

Description

@crusaderky

Describe the issue:

In numpy 2.0 nightly, applying sqrt() to a fully masked scalar array undoes the mask.
numpy 1.26.3 behaves correctly.
Other ufuncs seem to behave correctly (but I haven't performed a thorough test for all of them).

Reproduce the code example:

>>> import numpy as np
>>> a = np.ma.masked_array(1, mask=True)
>>> type(a)
numpy.ma.core.MaskedArray

>>> np.sqrt(a)
# numpy 2.0
masked_array(data=1.,
             mask=False,
             fill_value=1e+20)
# numpy 1.26.3
masked_array(data=--,
             mask=True,
       fill_value=1e+20,
            dtype=float64)

>>> np.sqrt(np.ma.masked)
# numpy 2.0
masked_array(data=0.,
             mask=False,
             fill_value=1e+20)
# numpy 1.26.3
masked_array(data=--,
             mask=True,
       fill_value=1e+20,
            dtype=float64)

Error message:

No response

Python and NumPy Versions:

CPython 3.12.1 x86_64
numpy 2.0.0.dev0+git20240113.d2f60ff

from
python -m pip install --no-deps --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
as of 2024-01-19

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions