[NumPy-Tickets] [NumPy] #1332: set_fill_value does not work properly for masked structured array
NumPy Trac
numpy-tickets@scipy....
Sun Feb 7 22:23:09 CST 2010
#1332: set_fill_value does not work properly for masked structured array
-------------------------+--------------------------------------------------
Reporter: robitaille | Owner: pierregm
Type: defect | Status: reopened
Priority: high | Milestone:
Component: numpy.ma | Version: devel
Resolution: | Keywords:
-------------------------+--------------------------------------------------
Comment(by robitaille):
The test code I posted works fine - however, I had strange problems with a
larger program and managed to narrow it down to the following example.
The following code works as expected:
{{{
import numpy.ma as ma
import numpy as np
dtype = ('dec', np.dtype('float64'))
a = ma.array([(1.,),(2.,),(3.,),(4.,)],
mask = [(False,),(False,),(False,),(False,)],
fill_value = (np.nan,),
dtype = [('ra', '<f8')])
newdtype = np.dtype([('ra', '<f8'), dtype])
b = ma.empty(a.shape, dtype=newdtype)
b['ra'] = a['ra']
print repr(b)
b['ra'].set_fill_value(a['ra'].fill_value)
print repr(b)
}}}
with the output:
{{{
masked_array(data = [(1.0, 2.1304385512215302e-314) (2.0,
2.1243859343164211e-314)
(3.0, 2.1304549062766045e-314) (4.0, 5.5626846462680035e-309)],
mask = [(False, False) (False, False) (False, False) (False,
False)],
fill_value = (1e+20, 1e+20),
dtype = [('ra', '<f8'), ('dec', '<f8')])
masked_array(data = [(1.0, 2.1304385512215302e-314) (2.0,
2.1243859343164211e-314)
(3.0, 2.1304549062766045e-314) (4.0, 5.5626846462680035e-309)],
mask = [(False, False) (False, False) (False, False) (False,
False)],
fill_value = (nan, 1e+20),
dtype = [('ra', '<f8'), ('dec', '<f8')])
}}}
However, simply commenting out the first print statement results in the
set_fill_value no longer having an effect:
{{{
import numpy.ma as ma
import numpy as np
dtype = ('dec', np.dtype('float64'))
a = ma.array([(1.,),(2.,),(3.,),(4.,)],
mask = [(False,),(False,),(False,),(False,)],
fill_value = (np.nan,),
dtype = [('ra', '<f8')])
newdtype = np.dtype([('ra', '<f8'), dtype])
b = ma.empty(a.shape, dtype=newdtype)
b['ra'] = a['ra']
# print repr(b)
b['ra'].set_fill_value(a['ra'].fill_value)
print repr(b)
}}}
gives output
{{{
masked_array(data = [(1.0, 2.1304385522096615e-314) (2.0,
2.1243859343164211e-314)
(3.0, 2.1304549062766045e-314) (4.0, 5.5626846462680035e-309)],
mask = [(False, False) (False, False) (False, False) (False,
False)],
fill_value = (1e+20, 1e+20),
dtype = [('ra', '<f8'), ('dec', '<f8')])
}}}
So essentially, the presence or absence of print repr(b) is changing
things.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1332#comment:9>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list