diff options
author | pierregm <pierregm@localhost> | 2008-05-26 22:15:29 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2008-05-26 22:15:29 +0000 |
commit | 47883f921adb249e8c58b03e375a8dc347cbbedd (patch) | |
tree | 6eca3fa4c4248dc7571b6f8f4df8a79e77f71734 | |
parent | 24caeed5a1dfc1a90cbfc27d0ac9c154cee0af58 (diff) | |
download | numpy-47883f921adb249e8c58b03e375a8dc347cbbedd.tar.gz |
core : __new__: keep the fill_value of the initializing object by default
mrecords: force _guessvartypes to return numpy.dtypes instead of types
-rw-r--r-- | numpy/ma/core.py | 3 | ||||
-rw-r--r-- | numpy/ma/mrecords.py | 11 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 0bf97b46e..5c38ff92b 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -1214,8 +1214,9 @@ class MaskedArray(numeric.ndarray): 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 diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py index e81b06c04..55551fbd0 100644 --- a/numpy/ma/mrecords.py +++ b/numpy/ma/mrecords.py @@ -664,11 +664,11 @@ on the first line. An exception is raised if the file is 3D or more. 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 @@ def fromtextfile(fname, delimitor=None, commentchar='#', missingchar='', 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) #.................................................................... diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index f6fef9e10..0d32282a8 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -811,9 +811,11 @@ class TestMA(NumpyTestCase): # 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 @@ class TestMiscFunctions(NumpyTestCase): ############################################################################### #------------------------------------------------------------------------------ if __name__ == "__main__": - NumpyTest().run() + NumpyTest('numpy.ma.core').run() |