[NumPy-Tickets] [NumPy] #1391: Fill value and empty arrays

NumPy Trac numpy-tickets@scipy....
Mon Feb 8 07:29:55 CST 2010


#1391: Fill value and empty arrays
------------------------+---------------------------------------------------
 Reporter:  robitaille  |       Owner:  pierregm
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:          
Component:  numpy.ma    |     Version:  devel   
 Keywords:              |  
------------------------+---------------------------------------------------
 I'm not sure if this is a bug report or feature request since I'm not sure
 what the intended behavior is.

 When a masked structured array field is copied from one array to another,
 the masks are copied, but I would expect the fill value to be copied too
 (which it isn't). Furthermore, ma.empty and ma.zeros don't accept a
 fill_value= argument. Therefore, one is forced to call set_fill_value
 after copying the field. For example:

 {{{
 import numpy.ma as ma
 import numpy as np

 a = ma.array([(1.,),(2.,),(3.,),(4.,)],
              mask = [(False,),(False,),(False,),(False,)],
        fill_value = (np.nan,),
             dtype = [('ra', '<f8')])

 newdtype = np.dtype([('ra', '<f8'), ('dec', '<f8')])

 b = ma.zeros(a.shape, dtype=newdtype)

 b['ra'] = a['ra']

 print repr(b)
 }}}

 produces:

 {{{
 masked_array(data = [(1.0, 0.0) (2.0, 0.0) (3.0, 0.0) (4.0, 0.0)],
              mask = [(False, False) (False, False) (False, False) (False,
 False)],
        fill_value = (1e+20, 1e+20),
             dtype = [('ra', '<f8'), ('dec', '<f8')])
 }}}

 when, as a user, I would expect:

 {{{
 masked_array(data = [(1.0, 0.0) (2.0, 0.0) (3.0, 0.0) (4.0, 0.0)],
              mask = [(False, False) (False, False) (False, False) (False,
 False)],
        fill_value = (nan, 1e+20),
             dtype = [('ra', '<f8'), ('dec', '<f8')])
 }}}

 And the only way to get the fill value correct is to explicitly add

 {{{
 b['ra'].set_fill_value(a['ra'))
 }}}

 When copying whole fields, should the fill value for that field not be
 copied too?

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1391>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list