summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2008-05-14 22:08:33 +0000
committerpierregm <pierregm@localhost>2008-05-14 22:08:33 +0000
commitd7c77aae2d0766c9af901b3b98a23b0fedd70dc5 (patch)
tree3df4d8b91677c64f0f64a53185052b2ded23bc0e /numpy/ma
parent8f60b4886081dbb6ba5ce0e6fc854473fd716151 (diff)
downloadnumpy-d7c77aae2d0766c9af901b3b98a23b0fedd70dc5.tar.gz
extras : dropped the m prefix in mediff1d, mvander, mpolyfit
mrecords: fixed __setitem__ to update the mask if needed.
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py3
-rw-r--r--numpy/ma/extras.py18
-rw-r--r--numpy/ma/mrecords.py3
-rw-r--r--numpy/ma/tests/test_extras.py26
-rw-r--r--numpy/ma/tests/test_mrecords.py10
5 files changed, 37 insertions, 23 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 8e1e71e0a..1f5f84f19 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -1354,7 +1354,8 @@ class MaskedArray(numeric.ndarray):
# raise IndexError, msg
if isinstance(indx, basestring):
ndarray.__setitem__(self._data,indx, getdata(value))
- warnings.warn("The mask is NOT affected!")
+ warnings.warn("MaskedArray.__setitem__ on fields: "\
+ "The mask is NOT affected!")
return
#....
if value is masked:
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index d44921b9e..fce070df5 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -16,14 +16,15 @@ __all__ = ['apply_along_axis', 'atleast_1d', 'atleast_2d', 'atleast_3d',
'column_stack','compress_cols','compress_rowcols', 'compress_rows',
'count_masked',
'dot','dstack',
- 'expand_dims',
+ 'ediff1d','expand_dims',
'flatnotmasked_contiguous','flatnotmasked_edges',
'hsplit','hstack',
'mask_cols','mask_rowcols','mask_rows','masked_all','masked_all_like',
- 'median','mediff1d','mpolyfit','mr_','mvander',
+ 'median','mr_',
'notmasked_contiguous','notmasked_edges',
+ 'polyfit',
'row_stack',
- 'vstack',
+ 'vander','vstack',
]
from itertools import groupby
@@ -579,7 +580,7 @@ def dot(a,b, strict=False):
return masked_array(d, mask=m)
#...............................................................................
-def mediff1d(array, to_end=None, to_begin=None):
+def ediff1d(array, to_end=None, to_begin=None):
"""Return the differences between consecutive elements of an
array, possibly with prefixed and/or appended values.
@@ -826,7 +827,7 @@ def notmasked_contiguous(a, axis=None):
#---- Polynomial fit ---
#####--------------------------------------------------------------------------
-def mvander(x, n=None):
+def vander(x, n=None):
"""%s
Notes
-----
@@ -839,7 +840,7 @@ def mvander(x, n=None):
return _vander
-def mpolyfit(x, y, deg, rcond=None, full=False):
+def polyfit(x, y, deg, rcond=None, full=False):
"""%s
Notes
@@ -874,7 +875,7 @@ def mpolyfit(x, y, deg, rcond=None, full=False):
if scale != 0 :
x = x / scale
# solve least squares equation for powers of x
- v = mvander(x, order)
+ v = vander(x, order)
c, resids, rank, s = _lstsq(v, y.filled(0), rcond)
# warn on rank reduction, which indicates an ill conditioned matrix
if rank != order and not full:
@@ -892,8 +893,7 @@ def mpolyfit(x, y, deg, rcond=None, full=False):
_g = globals()
for nfunc in ('vander', 'polyfit'):
- mfunc = "m%s" % nfunc
- _g[mfunc].func_doc = _g[mfunc].func_doc % getattr(np,nfunc).__doc__
+ _g[nfunc].func_doc = _g[nfunc].func_doc % getattr(np,nfunc).__doc__
diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py
index c4975d56b..e38ea3803 100644
--- a/numpy/ma/mrecords.py
+++ b/numpy/ma/mrecords.py
@@ -349,6 +349,9 @@ The fieldname base is either `_data` or `_mask`."""
def __setitem__(self, indx, value):
"Sets the given record to value."
MaskedArray.__setitem__(self, indx, value)
+ if isinstance(indx, basestring):
+ self._fieldmask[indx] = ma.getmaskarray(value)
+
#............................................
def __setslice__(self, i, j, value):
"Sets the slice described by [i,j] to `value`."
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 74e89f03f..6612e83a1 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -282,37 +282,37 @@ class Test2DFunctions(NumpyTestCase):
c = dot(b,a,False)
assert_equal(c, N.dot(b.filled(0),a.filled(0)))
- def test_mediff1d(self):
+ def test_ediff1d(self):
"Tests mediff1d"
x = masked_array(N.arange(5), mask=[1,0,0,0,1])
difx_d = (x._data[1:]-x._data[:-1])
difx_m = (x._mask[1:]-x._mask[:-1])
- dx = mediff1d(x)
+ dx = ediff1d(x)
assert_equal(dx._data, difx_d)
assert_equal(dx._mask, difx_m)
#
- dx = mediff1d(x, to_begin=masked)
+ dx = ediff1d(x, to_begin=masked)
assert_equal(dx._data, N.r_[0,difx_d])
assert_equal(dx._mask, N.r_[1,difx_m])
- dx = mediff1d(x, to_begin=[1,2,3])
+ dx = ediff1d(x, to_begin=[1,2,3])
assert_equal(dx._data, N.r_[[1,2,3],difx_d])
assert_equal(dx._mask, N.r_[[0,0,0],difx_m])
#
- dx = mediff1d(x, to_end=masked)
+ dx = ediff1d(x, to_end=masked)
assert_equal(dx._data, N.r_[difx_d,0])
assert_equal(dx._mask, N.r_[difx_m,1])
- dx = mediff1d(x, to_end=[1,2,3])
+ dx = ediff1d(x, to_end=[1,2,3])
assert_equal(dx._data, N.r_[difx_d,[1,2,3]])
assert_equal(dx._mask, N.r_[difx_m,[0,0,0]])
#
- dx = mediff1d(x, to_end=masked, to_begin=masked)
+ dx = ediff1d(x, to_end=masked, to_begin=masked)
assert_equal(dx._data, N.r_[0,difx_d,0])
assert_equal(dx._mask, N.r_[1,difx_m,1])
- dx = mediff1d(x, to_end=[1,2,3], to_begin=masked)
+ dx = ediff1d(x, to_end=[1,2,3], to_begin=masked)
assert_equal(dx._data, N.r_[0,difx_d,[1,2,3]])
assert_equal(dx._mask, N.r_[1,difx_m,[0,0,0]])
#
- dx = mediff1d(x._data, to_end=masked, to_begin=masked)
+ dx = ediff1d(x._data, to_end=masked, to_begin=masked)
assert_equal(dx._data, N.r_[0,difx_d,0])
assert_equal(dx._mask, N.r_[1,0,0,0,0,1])
@@ -362,24 +362,24 @@ class TestPolynomial(NumpyTestCase):
# On ndarrays
x = numpy.random.rand(10)
y = numpy.random.rand(20).reshape(-1,2)
- assert_almost_equal(mpolyfit(x,y,3),numpy.polyfit(x,y,3))
+ assert_almost_equal(polyfit(x,y,3),numpy.polyfit(x,y,3))
# ON 1D maskedarrays
x = x.view(MaskedArray)
x[0] = masked
y = y.view(MaskedArray)
y[0,0] = y[-1,-1] = masked
#
- (C,R,K,S,D) = mpolyfit(x,y[:,0],3,full=True)
+ (C,R,K,S,D) = polyfit(x,y[:,0],3,full=True)
(c,r,k,s,d) = numpy.polyfit(x[1:], y[1:,0].compressed(), 3, full=True)
for (a,a_) in zip((C,R,K,S,D),(c,r,k,s,d)):
assert_almost_equal(a, a_)
#
- (C,R,K,S,D) = mpolyfit(x,y[:,-1],3,full=True)
+ (C,R,K,S,D) = polyfit(x,y[:,-1],3,full=True)
(c,r,k,s,d) = numpy.polyfit(x[1:-1], y[1:-1,-1], 3, full=True)
for (a,a_) in zip((C,R,K,S,D),(c,r,k,s,d)):
assert_almost_equal(a, a_)
#
- (C,R,K,S,D) = mpolyfit(x,y,3,full=True)
+ (C,R,K,S,D) = polyfit(x,y,3,full=True)
(c,r,k,s,d) = numpy.polyfit(x[1:-1], y[1:-1,:], 3, full=True)
for (a,a_) in zip((C,R,K,S,D),(c,r,k,s,d)):
assert_almost_equal(a, a_)
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index cb550a9aa..910bd4234 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -120,6 +120,16 @@ class TestMRecords(NumpyTestCase):
mbase.b[3:] = masked
assert_equal(mbase.b, base['b'])
assert_equal(mbase.b._mask, [0,1,0,1,1])
+ # Set fields globally..........................
+ ndtype = [('alpha','|S1'),('num',int)]
+ data = ma.array([('a',1),('b',2),('c',3)], dtype=ndtype)
+ rdata = data.view(MaskedRecords)
+ val = ma.array([10,20,30], mask=[1,0,0])
+ #
+ rdata['num'] = val
+ assert_equal(rdata.num, val)
+ assert_equal(rdata.num.mask, [1,0,0])
+
#
def test_set_mask(self):
base = self.base.copy()