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

Skip to content

np.ma.masked_where(copy=False) fails to modify array in place when there were no masked elements in the array initially #18946

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

Closed
jacekt opened this issue May 8, 2021 · 1 comment · Fixed by #18967

Comments

@jacekt
Copy link

jacekt commented May 8, 2021

ma.masked_where documentation says that:

copy : bool
    If True (default) make a copy of `a` in the result.  If False modify
    `a` in place and return a view.

But it fails to modify the array's mask when the original mask is empty:

Reproducing code example:

>>> import numpy as np
>>> import numpy.ma as ma

>>> a = ma.array([1, 2, 3, 4])
>>> a
masked_array(data=[1, 2, 3, 4],
             mask=False,
       fill_value=999999)

>>> ma.masked_where(a==3, a, copy=False)
masked_array(data=[1, 2, --, 4],
             mask=[False, False,  True, False],
       fill_value=999999)

>>> a
masked_array(data=[1, 2, 3, 4],
             mask=False,
       fill_value=999999)

It works properly when there are some masked elements in the array already:

>>> a = ma.array([1, 2, 3, 4], mask=[1, 0, 0, 0])
>>> a
masked_array(data=[--, 2, 3, 4],
             mask=[ True, False, False, False],
       fill_value=999999)

>>> ma.masked_where(a==3, a, copy=False)
masked_array(data=[--, 2, --, 4],
             mask=[ True, False,  True, False],
       fill_value=999999)

>>> a
masked_array(data=[--, 2, --, 4],
             mask=[ True, False,  True, False],
       fill_value=999999)

Error message:

None.

NumPy/Python version information:

1.20.2 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]
numpy-1.20.2-cp38-cp38-win_amd64.whl

@jacekt jacekt changed the title np.ma.masked_where(copy=False) fails to modify array in place when there are no masked elements in the array np.ma.masked_where(copy=False) fails to modify array in place when there were no masked elements in the array initially May 9, 2021
@rgommers rgommers added this to the 1.21.0 release milestone May 10, 2021
@rgommers
Copy link
Member

Thanks for the report @jacekt. Fixed now.

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

Successfully merging a pull request may close this issue.

2 participants