summaryrefslogtreecommitdiff
path: root/numpy/ma/extras.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2011-12-06 21:37:47 -0700
committerCharles Harris <charlesr.harris@gmail.com>2011-12-15 09:13:27 -0700
commiteb042bf3bf192c3652b959c2f75ee79225b252b5 (patch)
treeda8b1b3d27757eca1be4e6fb4ec75686f1bfbbc6 /numpy/ma/extras.py
parent30964867d133f4ec2422e2cdf1cd69a28b7c45f1 (diff)
downloadnumpy-eb042bf3bf192c3652b959c2f75ee79225b252b5.tar.gz
BUG: Handle weight correctly and don't modify the original.
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r--numpy/ma/extras.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index 162890ee3..c5b3a3957 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -1852,22 +1852,27 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
x = asarray(x)
y = asarray(y)
- mx = getmask(x)
+ m = getmask(x)
if y.ndim == 1:
- m = mask_or(mx, getmask(y))
+ m = mask_or(m, getmask(y))
elif y.ndim == 2:
- y = mask_rows(y)
- my = getmask(y)
+ my = getmask(mask_rows(y))
if my is not nomask:
- m = mask_or(mx, my[:, 0])
- else:
- m = mx
+ m = mask_or(m, my[:, 0])
else:
raise TypeError("Expected a 1D or 2D array for y!")
+ if w is not None:
+ w = asarray(w)
+ if w.ndim != 1:
+ raise TypeError, "expected a 1-d array for weights"
+ if w.shape[0] != y.shape[0] :
+ raise TypeError, "expected w and y to have the same length"
+ m = mask_or(m, getmask(w))
+
if m is not nomask:
if w is not None:
- w *= ~m
+ w = ~m*w
else:
w = ~m