-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
BUG: Numpy ma diff skipping the mask when using argument 'prepend' #22465
Copy link
Copy link
Closed
Labels
Description
Describe the issue:
Hi ,
I have realized that when I pass a masked array in numpy ma diff np.ma.diff and prepend a masked intial value, the mask is deleted and replaced (in my case for 0. values). Despite being the fill_value different from 0.
I would expect that np.ma.diff keeps the mask after calculating the difference, specifically if you are prepending a masked array that keeps the same structure than the input array.
See below:
Reproduce the code example:
import numpy as np
# a is the dummy array
a = np.random.randn(5,10,10)
a = np.ma.masked_where(a<.1,a)
print(a.mask.any()) # returns True
b = np.ma.diff(a, prepend=a[:1,...],axis=0)
print(b.mask.any()) # returns False (unexpected)
# What I would expect / my workaround
c = np.ma.diff(np.ma.append(a[:1], a, axis=0),axis=0)
print(c.mask.any()) # returns True (as expected)NumPy/Python version information:
My numpy version is: '1.23.4'
Python version is: 3.10.6
Context for the issue:
Shouldn't np.ma module's objects respect always the input mask (if it is properly referenced in its arguments)?
Thanks a lot and keep on with the amazing numpy!
Reactions are currently unavailable