[Numpy-tickets] [NumPy] #642: maskedarray concatenate does not handle nomask right (unlike numpy.core.ma)

NumPy numpy-tickets@scipy....
Wed Jan 9 15:41:23 CST 2008


#642: maskedarray concatenate does not handle nomask right (unlike numpy.core.ma)
---------------------+------------------------------------------------------
 Reporter:  bsulman  |       Owner:  somebody   
     Type:  defect   |      Status:  new        
 Priority:  normal   |   Milestone:             
Component:  Other    |     Version:  none       
 Severity:  normal   |    Keywords:  maskedarray
---------------------+------------------------------------------------------
 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 (branches/maskedarray/numpy/ma/core.py
 line 2735 as of revision 4625):

 ...
 {{{
     # 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 filed this under scipy originally.  Looks like maskedarray was moved to
 numpy.  Sorry if this showed up twice for people.

-- 
Ticket URL: <http://scipy.org/scipy/numpy/ticket/642>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list