Skip to content

Cannot unmask structured arrays values based on predicate #22049

@paolomattioli1989

Description

@paolomattioli1989

There seems to be an issue when trying to unmask a value in a structured array based on some predicate.
I would have expected this operation to successfully unmask the entry, but it does not - see the example below.

I'm running Ubuntu 20.04.3 and python 3.8.13
This behaviour has been observed on numpy versions 1.23.1 and 1.22.4 (the two ones i've tried).
The expected behaviour (so no AssertionError raised by the below snippet) is instead observed in 1.21.5.

out = np.ma.array(np.empty(3, dtype=[('a_string', '<U30'), ('a_float', '<f8')]), mask=True)
assert not out.hardmask
out['a_string'] = ['Aa', 'Bb', 'Cc']
pred = out['a_string'] == 'Aa'
assert pred.sum() == 1
out['a_float'][pred] = 1.23

assert not out['a_float'][pred].mask.item()  # <-- fails

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