[Numpy-svn] r5242 - in trunk/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon May 26 18:15:32 EDT 2008
Author: pierregm
Date: 2008-05-26 17:15:29 -0500 (Mon, 26 May 2008)
New Revision: 5242
Modified:
trunk/numpy/ma/core.py
trunk/numpy/ma/mrecords.py
trunk/numpy/ma/tests/test_core.py
Log:
core : __new__: keep the fill_value of the initializing object by default
mrecords: force _guessvartypes to return numpy.dtypes instead of types
Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py 2008-05-26 22:08:35 UTC (rev 5241)
+++ trunk/numpy/ma/core.py 2008-05-26 22:15:29 UTC (rev 5242)
@@ -1214,8 +1214,9 @@
else:
_data._mask = umath.logical_or(mask, _data._mask)
_data._sharedmask = False
-
# Update fill_value.......
+ if fill_value is None:
+ fill_value = getattr(data,'_fill_value', None)
_data._fill_value = _check_fill_value(fill_value, _data.dtype)
# Process extra options ..
_data._hardmask = hard_mask
Modified: trunk/numpy/ma/mrecords.py
===================================================================
--- trunk/numpy/ma/mrecords.py 2008-05-26 22:08:35 UTC (rev 5241)
+++ trunk/numpy/ma/mrecords.py 2008-05-26 22:15:29 UTC (rev 5242)
@@ -664,11 +664,11 @@
except ValueError:
vartypes.append(arr.dtype)
else:
- vartypes.append(complex)
+ vartypes.append(np.dtype(complex))
else:
- vartypes.append(float)
+ vartypes.append(np.dtype(float))
else:
- vartypes.append(int)
+ vartypes.append(np.dtype(int))
return vartypes
def openfile(fname):
@@ -738,11 +738,12 @@
vartypes = _guessvartypes(_variables[0])
# Construct the descriptor ..................
mdescr = [(n,f) for (n,f) in zip(varnames, vartypes)]
+ mfillv = [ma.default_fill_value(f) for f in vartypes]
# Get the data and the mask .................
# We just need a list of masked_arrays. It's easier to create it like that:
_mask = (_variables.T == missingchar)
- _datalist = [masked_array(a,mask=m,dtype=t)
- for (a,m,t) in zip(_variables.T, _mask, vartypes)]
+ _datalist = [masked_array(a,mask=m,dtype=t,fill_value=f)
+ for (a,m,t,f) in zip(_variables.T, _mask, vartypes, mfillv)]
return fromarrays(_datalist, dtype=mdescr)
#....................................................................
Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py 2008-05-26 22:08:35 UTC (rev 5241)
+++ trunk/numpy/ma/tests/test_core.py 2008-05-26 22:15:29 UTC (rev 5242)
@@ -811,9 +811,11 @@
#
def test_asarray(self):
(x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
+ xm.fill_value = -9999
xmm = asarray(xm)
assert_equal(xmm._data, xm._data)
assert_equal(xmm._mask, xm._mask)
+ assert_equal(xmm.fill_value, xm.fill_value)
#
def test_fix_invalid(self):
"Checks fix_invalid."
@@ -1588,4 +1590,4 @@
###############################################################################
#------------------------------------------------------------------------------
if __name__ == "__main__":
- NumpyTest().run()
+ NumpyTest('numpy.ma.core').run()
More information about the Numpy-svn
mailing list