summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py3
-rw-r--r--numpy/ma/mrecords.py11
-rw-r--r--numpy/ma/tests/test_core.py4
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()