8000 MaskedArray recarray, multi-dimensional field + set_fill_value = exception · Issue #9748 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MaskedArray recarray, multi-dimensional field + set_fill_value = exception #9748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LevN0 opened this issue Sep 23, 2017 · 1 comment
Open

Comments

@LevN0
Copy link
LevN0 commented Sep 23, 2017

A bug was introduced in fix for #6723,

x = np.array([([0, 0], 0.0), ([2, 2], 3.0)],
              dtype=[('field1', 'i4', (2,)), ('field2', 'f4')])
y = x.view(np.ma.MaskedArray)

y['field1'].set_fill_value(5)

Produces,

  File "...\numpy\ma\core.py", line 3615, in set_fill_value
    _fill_value[()] = target
TypeError: 'numpy.int32' object does not support item assignment

The reason is that np.ma.MaskedArray._fill_value should be a zero-length array, containing the fill value. However the fix in that issue simply sets it to be a value (e.g. one with dtype numpy.int32), not a zero-length array.

@eric-wieser
Copy link
Member
eric-wieser commented Sep 23, 2017

Nice catch! You mean zero-dimensional array though.

A simple fix would be to change this line to dout._fill_value = dout._fill_value.ravel()[0,...]. It's unfortunately slower to use ravel than flat, but that's a corner case anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0