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

Skip to content

Inconsistency of np.clip with MaskedArray when using output argument #14140

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
bingyao opened this issue Jul 27, 2019 · 1 comment · Fixed by #14145
Closed

Inconsistency of np.clip with MaskedArray when using output argument #14140

bingyao opened this issue Jul 27, 2019 · 1 comment · Fixed by #14145

Comments

@bingyao
Copy link

bingyao commented Jul 27, 2019

Reproducing code example:

In [1]: import numpy as np                                                                                                                                                 

In [2]: np.__version__                                                                                                                                                     
Out[2]: '1.17.0'

In [3]: a = np.arange(10)                                                                                                                                                  

In [4]: m = np.ma.MaskedArray(a, mask=[0, 1] * 5)                                                                                                                          

In [5]: np.clip(m, 0, 5)                                                                                                                                                   
Out[5]: 
masked_array(data=[0, --, 2, --, 4, --, 5, --, 5, --],
             mask=[False,  True, False,  True, False,  True, False,  True,
                   False,  True],
       fill_value=999999)

In [6]: m                                                                                                                                                                  
Out[6]: 
masked_array(data=[0, --, 2, --, 4, --, 6, --, 8, --],
             mask=[False,  True, False,  True, False,  True, False,  True,
                   False,  True],
       fill_value=999999)

In [7]: np.clip(m, 0, 5, m)                                                                                                                                                
Out[7]: 
masked_array(data=[0, 1, 2, 3, 4, 5, 5, 5, 5, 5],
             mask=False,
       fill_value=999999)

In [8]: m                                                                                                                                                                  
Out[8]: 
masked_array(data=[0, 1, 2, 3, 4, 5, 5, 5, 5, 5],
             mask=False,
       fill_value=999999)

Error message:

Inconsistency of np.clip with MaskedArray when using output argument. I.e.:

np.clip(m, 0, 5)
np.clip(m, 0, 5, m)

these two lines produce different results.

Numpy/Python version information:

Python: 3.7.3
Numpy: 1.17.0

@bingyao bingyao changed the title Inconsistency of np.clip with MaskedArray when using output argument Inconsistency of np.clip with MaskedArray when using output argument Jul 27, 2019
@eric-wieser
Copy link
Member

eric-wieser commented Jul 28, 2019

fallout from #12519. Easy workaround for 1.17.0 is

del np.ma.MaskedArray.clip

Fix will be to remove the definition of the method, the one inherited from ndarray works correctly.

eric-wieser added a commit to eric-wieser/numpy that referenced this issue Jul 28, 2019
ndarray.clip is already just a wrapper for the ufunc, so there is no need to do type-specific wrapping here any more

Fixes numpygh-14140
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