diff options
author | Travis E. Oliphant <teoliphant@gmail.com> | 2012-06-21 01:37:01 -0700 |
---|---|---|
committer | Travis E. Oliphant <teoliphant@gmail.com> | 2012-06-21 01:37:01 -0700 |
commit | 134174c9265dd87ea802c89cac7a89478e3184f4 (patch) | |
tree | 5ec76af2359d8b038175fc2df3754c642c708805 /numpy/polynomial | |
parent | 651ef74c4ebe7d24e727fd444b1985117ef16fae (diff) | |
parent | 3626d0c4fe510d615ef3e5ef3cf4ed2bfb52b53e (diff) | |
download | numpy-134174c9265dd87ea802c89cac7a89478e3184f4.tar.gz |
Merge pull request #297 from njsmith/separate-maskna
Split maskna support out of mainline into a branch
Diffstat (limited to 'numpy/polynomial')
-rw-r--r-- | numpy/polynomial/chebyshev.py | 13 | ||||
-rw-r--r-- | numpy/polynomial/hermite.py | 13 | ||||
-rw-r--r-- | numpy/polynomial/hermite_e.py | 13 | ||||
-rw-r--r-- | numpy/polynomial/laguerre.py | 13 | ||||
-rw-r--r-- | numpy/polynomial/legendre.py | 13 | ||||
-rw-r--r-- | numpy/polynomial/polynomial.py | 29 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_chebyshev.py | 30 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_hermite.py | 30 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_hermite_e.py | 30 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_laguerre.py | 30 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_legendre.py | 30 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_polynomial.py | 30 |
12 files changed, 10 insertions, 264 deletions
diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py index 6fbd5d346..00cac2527 100644 --- a/numpy/polynomial/chebyshev.py +++ b/numpy/polynomial/chebyshev.py @@ -1452,9 +1452,8 @@ def chebvander(x, deg) : x = np.array(x, copy=0, ndmin=1) + 0.0 dims = (ideg + 1,) + x.shape - mask = x.flags.maskna dtyp = x.dtype - v = np.empty(dims, dtype=dtyp, maskna=mask) + v = np.empty(dims, dtype=dtyp) # Use forward recursion to generate the entries. v[0] = x*0 + 1 if ideg > 0 : @@ -1739,16 +1738,6 @@ def chebfit(x, y, deg, rcond=None, full=False, w=None): lhs = lhs * w rhs = rhs * w - # deal with NA. Note that polyvander propagates NA from x - # into all columns, that is rows for transposed form. - if lhs.flags.maskna or rhs.flags.maskna: - if rhs.ndim == 1: - mask = np.isna(lhs[0]) | np.isna(rhs) - else: - mask = np.isna(lhs[0]) | np.isna(rhs).any(0) - np.copyto(lhs, 0, where=mask) - np.copyto(rhs, 0, where=mask) - # set rcond if rcond is None : rcond = len(x)*np.finfo(x.dtype).eps diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index 229ac26db..0b637f40a 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -1225,9 +1225,8 @@ def hermvander(x, deg) : x = np.array(x, copy=0, ndmin=1) + 0.0 dims = (ideg + 1,) + x.shape - mask = x.flags.maskna dtyp = x.dtype - v = np.empty(dims, dtype=dtyp, maskna=mask) + v = np.empty(dims, dtype=dtyp) v[0] = x*0 + 1 if ideg > 0 : x2 = x*2 @@ -1516,16 +1515,6 @@ def hermfit(x, y, deg, rcond=None, full=False, w=None): lhs = lhs * w rhs = rhs * w - # deal with NA. Note that polyvander propagates NA from x - # into all columns, that is rows for transposed form. - if lhs.flags.maskna or rhs.flags.maskna: - if rhs.ndim == 1: - mask = np.isna(lhs[0]) | np.isna(rhs) - else: - mask = np.isna(lhs[0]) | np.isna(rhs).any(0) - np.copyto(lhs, 0, where=mask) - np.copyto(rhs, 0, where=mask) - # set rcond if rcond is None : rcond = len(x)*np.finfo(x.dtype).eps diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py index ba41a4fc0..c5abe03ca 100644 --- a/numpy/polynomial/hermite_e.py +++ b/numpy/polynomial/hermite_e.py @@ -1222,9 +1222,8 @@ def hermevander(x, deg) : x = np.array(x, copy=0, ndmin=1) + 0.0 dims = (ideg + 1,) + x.shape - mask = x.flags.maskna dtyp = x.dtype - v = np.empty(dims, dtype=dtyp, maskna=mask) + v = np.empty(dims, dtype=dtyp) v[0] = x*0 + 1 if ideg > 0 : v[1] = x @@ -1512,16 +1511,6 @@ def hermefit(x, y, deg, rcond=None, full=False, w=None): lhs = lhs * w rhs = rhs * w - # deal with NA. Note that polyvander propagates NA from x - # into all columns, that is rows for transposed form. - if lhs.flags.maskna or rhs.flags.maskna: - if rhs.ndim == 1: - mask = np.isna(lhs[0]) | np.isna(rhs) - else: - mask = np.isna(lhs[0]) | np.isna(rhs).any(0) - np.copyto(lhs, 0, where=mask) - np.copyto(rhs, 0, where=mask) - # set rcond if rcond is None : rcond = len(x)*np.finfo(x.dtype).eps diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py index 4401b5414..3533343b0 100644 --- a/numpy/polynomial/laguerre.py +++ b/numpy/polynomial/laguerre.py @@ -1225,9 +1225,8 @@ def lagvander(x, deg) : x = np.array(x, copy=0, ndmin=1) + 0.0 dims = (ideg + 1,) + x.shape - mask = x.flags.maskna dtyp = x.dtype - v = np.empty(dims, dtype=dtyp, maskna=mask) + v = np.empty(dims, dtype=dtyp) v[0] = x*0 + 1 if ideg > 0 : v[1] = 1 - x @@ -1515,16 +1514,6 @@ def lagfit(x, y, deg, rcond=None, full=False, w=None): lhs = lhs * w rhs = rhs * w - # deal with NA. Note that polyvander propagates NA from x - # into all columns, that is rows for transposed form. - if lhs.flags.maskna or rhs.flags.maskna: - if rhs.ndim == 1: - mask = np.isna(lhs[0]) | np.isna(rhs) - else: - mask = np.isna(lhs[0]) | np.isna(rhs).any(0) - np.copyto(lhs, 0, where=mask) - np.copyto(rhs, 0, where=mask) - # set rcond if rcond is None : rcond = len(x)*np.finfo(x.dtype).eps diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index 9470865a8..1216e29f4 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -1253,9 +1253,8 @@ def legvander(x, deg) : x = np.array(x, copy=0, ndmin=1) + 0.0 dims = (ideg + 1,) + x.shape - mask = x.flags.maskna dtyp = x.dtype - v = np.empty(dims, dtype=dtyp, maskna=mask) + v = np.empty(dims, dtype=dtyp) # Use forward recursion to generate the entries. This is not as accurate # as reverse recursion in this application but it is more efficient. v[0] = x*0 + 1 @@ -1540,16 +1539,6 @@ def legfit(x, y, deg, rcond=None, full=False, w=None): lhs = lhs * w rhs = rhs * w - # deal with NA. Note that polyvander propagates NA from x - # into all columns, that is rows for transposed form. - if lhs.flags.maskna or rhs.flags.maskna: - if rhs.ndim == 1: - mask = np.isna(lhs[0]) | np.isna(rhs) - else: - mask = np.isna(lhs[0]) | np.isna(rhs).any(0) - np.copyto(lhs, 0, where=mask) - np.copyto(rhs, 0, where=mask) - # set rcond if rcond is None : rcond = len(x)*np.finfo(x.dtype).eps diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 7a5d3dbd5..324bec9c0 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -205,7 +205,7 @@ def polyadd(c1, c2): Returns the sum of two polynomials `c1` + `c2`. The arguments are sequences of coefficients from lowest order term to highest, i.e., - [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2"``. + [1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``. Parameters ---------- @@ -524,12 +524,9 @@ def polyder(c, m=1, scl=1, axis=0): """ c = np.array(c, ndmin=1, copy=1) - if c.flags.maskna and isna(c).any(): - raise ValueError("Coefficient array contains NA") if c.dtype.char in '?bBhHiIlLqQpP': # astype fails with NA c = c + 0.0 - mna = c.flags.maskna cdt = c.dtype cnt, iaxis = [int(t) for t in [m, axis]] @@ -555,7 +552,7 @@ def polyder(c, m=1, scl=1, axis=0): for i in range(cnt): n = n - 1 c *= scl - der = np.empty((n,) + c.shape[1:], dtype=cdt, maskna=mna) + der = np.empty((n,) + c.shape[1:], dtype=cdt) for j in range(n, 0, -1): der[j - 1] = j*c[j] c = der @@ -641,12 +638,9 @@ def polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0): """ c = np.array(c, ndmin=1, copy=1) - if c.flags.maskna and isna(c).any(): - raise ValueError("Coefficient array contains NA") - elif c.dtype.char in '?bBhHiIlLqQpP': + if c.dtype.char in '?bBhHiIlLqQpP': # astype doesn't preserve mask attribute. c = c + 0.0 - mna = c.flags.maskna cdt = c.dtype if not np.iterable(k): k = [k] @@ -677,7 +671,7 @@ def polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if n == 1 and np.all(c[0] == 0): c[0] += k[i] else: - tmp = np.empty((n + 1,) + c.shape[1:], dtype=cdt, maskna=mna) + tmp = np.empty((n + 1,) + c.shape[1:], dtype=cdt) tmp[0] = c[0]*0 tmp[1] = c[0] for j in range(1, n): @@ -770,8 +764,6 @@ def polyval(x, c, tensor=True): """ c = np.array(c, ndmin=1, copy=0) - if c.flags.maskna and isna(c).any(): - raise ValueError("Coefficient array contains NA") if c.dtype.char in '?bBhHiIlLqQpP': # astype fails with NA c = c + 0.0 @@ -1062,9 +1054,8 @@ def polyvander(x, deg) : x = np.array(x, copy=0, ndmin=1) + 0.0 dims = (ideg + 1,) + x.shape - mask = x.flags.maskna dtyp = x.dtype - v = np.empty(dims, dtype=dtyp, maskna=mask) + v = np.empty(dims, dtype=dtyp) v[0] = x*0 + 1 if ideg > 0 : v[1] = x @@ -1370,16 +1361,6 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None): lhs = lhs * w rhs = rhs * w - # deal with NA. Note that polyvander propagates NA from x - # into all columns, that is rows for transposed form. - if lhs.flags.maskna or rhs.flags.maskna: - if rhs.ndim == 1: - mask = np.isna(lhs[0]) | np.isna(rhs) - else: - mask = np.isna(lhs[0]) | np.isna(rhs).any(0) - np.copyto(lhs, 0, where=mask) - np.copyto(rhs, 0, where=mask) - # set rcond if rcond is None : rcond = len(x)*np.finfo(x.dtype).eps diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py index 5e6d5632b..331cc17bc 100644 --- a/numpy/polynomial/tests/test_chebyshev.py +++ b/numpy/polynomial/tests/test_chebyshev.py @@ -436,36 +436,6 @@ class TestFitting(TestCase): wcoef2d = cheb.chebfit(x, np.array([yw,yw]).T, 3, w=w) assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) - #test NA - y = f(x) - y[10] = 100 - - xm = x.view(maskna=1) - xm[10] = np.NA - res = cheb.chebfit(xm, y, 3) - assert_almost_equal(res, coef3) - - ym = y.view(maskna=1) - ym[10] = np.NA - res = cheb.chebfit(x, ym, 3) - assert_almost_equal(res, coef3) - - y2 = np.vstack((y,y)).T - y2[10,0] = 100 - y2[15,1] = 100 - y2m = y2.view(maskna=1) - y2m[10,0] = np.NA - y2m[15,1] = np.NA - res = cheb.chebfit(x, y2m, 3).T - assert_almost_equal(res[0], coef3) - assert_almost_equal(res[1], coef3) - - wm = np.ones_like(x, maskna=1) - wm[10] = np.NA - res = cheb.chebfit(x, y, 3, w=wm) - assert_almost_equal(res, coef3) - - class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_hermite.py b/numpy/polynomial/tests/test_hermite.py index 425ebe5e0..b5649a693 100644 --- a/numpy/polynomial/tests/test_hermite.py +++ b/numpy/polynomial/tests/test_hermite.py @@ -426,36 +426,6 @@ class TestFitting(TestCase): wcoef2d = herm.hermfit(x, np.array([yw,yw]).T, 3, w=w) assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) - #test NA - y = f(x) - y[10] = 100 - - xm = x.view(maskna=1) - xm[10] = np.NA - res = herm.hermfit(xm, y, 3) - assert_almost_equal(res, coef3) - - ym = y.view(maskna=1) - ym[10] = np.NA - res = herm.hermfit(x, ym, 3) - assert_almost_equal(res, coef3) - - y2 = np.vstack((y,y)).T - y2[10,0] = 100 - y2[15,1] = 100 - y2m = y2.view(maskna=1) - y2m[10,0] = np.NA - y2m[15,1] = np.NA - res = herm.hermfit(x, y2m, 3).T - assert_almost_equal(res[0], coef3) - assert_almost_equal(res[1], coef3) - - wm = np.ones_like(x, maskna=1) - wm[10] = np.NA - res = herm.hermfit(x, y, 3, w=wm) - assert_almost_equal(res, coef3) - - class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_hermite_e.py b/numpy/polynomial/tests/test_hermite_e.py index f0ecb66b8..018fe8595 100644 --- a/numpy/polynomial/tests/test_hermite_e.py +++ b/numpy/polynomial/tests/test_hermite_e.py @@ -423,36 +423,6 @@ class TestFitting(TestCase): wcoef2d = herme.hermefit(x, np.array([yw,yw]).T, 3, w=w) assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) - #test NA - y = f(x) - y[10] = 100 - - xm = x.view(maskna=1) - xm[10] = np.NA - res = herme.hermefit(xm, y, 3) - assert_almost_equal(res, coef3) - - ym = y.view(maskna=1) - ym[10] = np.NA - res = herme.hermefit(x, ym, 3) - assert_almost_equal(res, coef3) - - y2 = np.vstack((y,y)).T - y2[10,0] = 100 - y2[15,1] = 100 - y2m = y2.view(maskna=1) - y2m[10,0] = np.NA - y2m[15,1] = np.NA - res = herme.hermefit(x, y2m, 3).T - assert_almost_equal(res[0], coef3) - assert_almost_equal(res[1], coef3) - - wm = np.ones_like(x, maskna=1) - wm[10] = np.NA - res = herme.hermefit(x, y, 3, w=wm) - assert_almost_equal(res, coef3) - - class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_laguerre.py b/numpy/polynomial/tests/test_laguerre.py index 8b3fd5f8a..14fafe37d 100644 --- a/numpy/polynomial/tests/test_laguerre.py +++ b/numpy/polynomial/tests/test_laguerre.py @@ -421,36 +421,6 @@ class TestFitting(TestCase): wcoef2d = lag.lagfit(x, np.array([yw,yw]).T, 3, w=w) assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) - #test NA - y = f(x) - y[10] = 100 - - xm = x.view(maskna=1) - xm[10] = np.NA - res = lag.lagfit(xm, y, 3) - assert_almost_equal(res, coef3) - - ym = y.view(maskna=1) - ym[10] = np.NA - res = lag.lagfit(x, ym, 3) - assert_almost_equal(res, coef3) - - y2 = np.vstack((y,y)).T - y2[10,0] = 100 - y2[15,1] = 100 - y2m = y2.view(maskna=1) - y2m[10,0] = np.NA - y2m[15,1] = np.NA - res = lag.lagfit(x, y2m, 3).T - assert_almost_equal(res[0], coef3) - assert_almost_equal(res[1], coef3) - - wm = np.ones_like(x, maskna=1) - wm[10] = np.NA - res = lag.lagfit(x, y, 3, w=wm) - assert_almost_equal(res, coef3) - - class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py index c7b71fc05..cdfaa96f1 100644 --- a/numpy/polynomial/tests/test_legendre.py +++ b/numpy/polynomial/tests/test_legendre.py @@ -424,36 +424,6 @@ class TestFitting(TestCase): wcoef2d = leg.legfit(x, np.array([yw,yw]).T, 3, w=w) assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) - #test NA - y = f(x) - y[10] = 100 - - xm = x.view(maskna=1) - xm[10] = np.NA - res = leg.legfit(xm, y, 3) - assert_almost_equal(res, coef3) - - ym = y.view(maskna=1) - ym[10] = np.NA - res = leg.legfit(x, ym, 3) - assert_almost_equal(res, coef3) - - y2 = np.vstack((y,y)).T - y2[10,0] = 100 - y2[15,1] = 100 - y2m = y2.view(maskna=1) - y2m[10,0] = np.NA - y2m[15,1] = np.NA - res = leg.legfit(x, y2m, 3).T - assert_almost_equal(res[0], coef3) - assert_almost_equal(res[1], coef3) - - wm = np.ones_like(x, maskna=1) - wm[10] = np.NA - res = leg.legfit(x, y, 3, w=wm) - assert_almost_equal(res, coef3) - - class TestGauss(TestCase): def test_100(self): diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py index 4854f95ee..bae711cbf 100644 --- a/numpy/polynomial/tests/test_polynomial.py +++ b/numpy/polynomial/tests/test_polynomial.py @@ -441,36 +441,6 @@ class TestMisc(TestCase) : wcoef2d = poly.polyfit(x, np.array([yw,yw]).T, 3, w=w) assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) - #test NA - y = f(x) - y[10] = 100 - - xm = x.view(maskna=1) - xm[10] = np.NA - res = poly.polyfit(xm, y, 3) - assert_almost_equal(res, coef3) - - ym = y.view(maskna=1) - ym[10] = np.NA - res = poly.polyfit(x, ym, 3) - assert_almost_equal(res, coef3) - - y2 = np.vstack((y,y)).T - y2[10,0] = 100 - y2[15,1] = 100 - y2m = y2.view(maskna=1) - y2m[10,0] = np.NA - y2m[15,1] = np.NA - res = poly.polyfit(x, y2m, 3).T - assert_almost_equal(res[0], coef3) - assert_almost_equal(res[1], coef3) - - wm = np.ones_like(x, maskna=1) - wm[10] = np.NA - res = poly.polyfit(x, y, 3, w=wm) - assert_almost_equal(res, coef3) - - def test_polytrim(self) : coef = [2, -1, 1, 0] |