[Scipy-tickets] [SciPy] #559: concatenate in maskedarray ignores masks after first nomask

SciPy scipy-tickets@scipy....
Wed Dec 12 12:47:59 CST 2007


#559: concatenate in maskedarray ignores masks after first nomask
---------------------+------------------------------------------------------
 Reporter:  bsulman  |       Owner:  somebody
     Type:  defect   |      Status:  new     
 Priority:  normal   |   Milestone:  0.7     
Component:  Other    |     Version:          
 Severity:  major    |    Keywords:          
---------------------+------------------------------------------------------
 When concatenating masked arrays in maskedarray, if one array has mask
 nomask, all arrays after are treated as nomask.

 Example:

 In [1]: import maskedarray as MA

 In [2]:
 x=MA.zeros(5);y=MA.ones(5);m=MA.zeros(5);m[3]=1;y=MA.array(y,mask=m)

 In [3]: MA.concatenate((x,y))

 Out[3]:
 masked_array(data = [ 0.  0.  0.  0.  0.  1.  1.  1.  1.  1.],
       mask = False,
       fill_value=1e+20)

 In [6]: MA.concatenate((y,x))

 Out[6]:
 masked_array(data = [1.0 1.0 1.0 -- 1.0 0.0 0.0 0.0 0.0 0.0],
       mask = [False False False  True False False False False False
 False],
       fill_value=1e+20)

 The reason for this:
 in the code (maskedarray/core.py line 2535):

 ...
     # Check whether one of the arrays has a non-empty mask...
     for x in arrays:
         if getmask(x) is not nomask:
             break
         return data
     # OK, so we have to concatenate the masks
 ...

 This returns the data as soon as it hits an array that has mask=nomask

 'return data' should be put in an else clause as appears in numpy.core.ma:

     for x in arrays:
         if getmask(x) is not nomask: break
     else:
         return masked_array(d)

 corrected maskedarray code:

 ...
     # Check whether one of the arrays has a non-empty mask...
     for x in arrays:
         if getmask(x) is not nomask:
             break
     else:
         return data
     # OK, so we have to concatenate the masks
 ...

 I hope I'm filing this in the right place.  I'm a little new to open
 source projects.

-- 
Ticket URL: <http://www.scipy.org/scipy/scipy/ticket/559>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list