summaryrefslogtreecommitdiff
path: root/numpy/polynomial/polynomial.py
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2012-05-11 14:31:50 +0100
committerNathaniel J. Smith <njs@pobox.com>2012-06-16 10:45:38 +0100
commitb272bc605ce7784be5b3edb13ad7afe22b04e71f (patch)
tree40fc10c60fd1b48d94be48a80e7cfc98525bd6e7 /numpy/polynomial/polynomial.py
parent1b6582d98c58afd977a69ac49f7e8e0d08a800b8 (diff)
downloadnumpy-b272bc605ce7784be5b3edb13ad7afe22b04e71f.tar.gz
Remove maskna API from ndarray, and all (and only) the code supporting it
The original masked-NA-NEP branch contained a large number of changes in addition to the core NA support. For example: - ufunc.__call__ support for where= argument - nditer support for arbitrary masks (in support of where=) - ufunc.reduce support for simultaneous reduction over multiple axes - a new "array assignment API" - ndarray.diagonal() returning a view in all cases - bug-fixes in __array_priority__ handling - datetime test changes etc. There's no consensus yet on what should be done with the maskna-related part of this branch, but the rest is generally useful and uncontroversial, so the goal of this branch is to identify exactly which code changes are involved in maskna support. The basic strategy used to create this patch was: - Remove the new masking-related fields from ndarray, so no arrays are masked - Go through and remove all the code that this makes dead/inaccessible/irrelevant, in a largely mechanical fashion. So for example, if I saw 'if (PyArray_HASMASK(a)) { ... }' then that whole block was obviously just dead code if no arrays have masks, and I removed it. Likewise for function arguments like skipna that are useless if there aren't any NAs to skip. This changed the signature of a number of functions that were newly exposed in the numpy public API. I've removed all such functions from the public API, since releasing them with the NA-less signature in 1.7 would create pointless compatibility hassles later if and when we add back the NA-related functionality. Most such functions are removed by this commit; the exception is PyArray_ReduceWrapper, which requires more extensive surgery, and will be handled in followup commits. I also removed the new ndarray.setasflat method. Reason: a comment noted that the only reason this was added was to allow easier testing of one branch of PyArray_CopyAsFlat. That branch is now the main branch, so that isn't an issue. Nonetheless this function is arguably useful, so perhaps it should have remained, but I judged that since numpy's API is already hairier than we would like, it's not a good idea to add extra hair "just in case". (Also AFAICT the test for this method in test_maskna was actually incorrect, as noted here: https://github.com/njsmith/numpyNEP/blob/master/numpyNEP.py so I'm not confident that it ever worked in master, though I haven't had a chance to follow-up on this.) I also removed numpy.count_reduce_items, since without skipna it became trivial. I believe that these are the only exceptions to the "remove dead code" strategy.
Diffstat (limited to 'numpy/polynomial/polynomial.py')
-rw-r--r--numpy/polynomial/polynomial.py29
1 files changed, 5 insertions, 24 deletions
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