diff options
author | David Schaich <daschaich@gmail.com> | 2016-05-24 19:31:51 -0400 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-06-15 11:23:20 -0600 |
commit | 37ee08dc9c7cbe0cf8a671c8cc73877d1a142ee1 (patch) | |
tree | 4cf82499dbcfd0897c5e0c7fd15544eb17bdc1e2 /numpy/lib/polynomial.py | |
parent | e26738a628de0fe1897f2960708ec16e4c3177f7 (diff) | |
download | numpy-37ee08dc9c7cbe0cf8a671c8cc73877d1a142ee1.tar.gz |
BUG: Make sure we don't divide by zero in np.polyfit.
This should fix the issue discussed at
https://mail.scipy.org/pipermail/numpy-discussion/2013-July/067076.html
Without the ValueError added here, polyfit can (and does) return
negative or nan variances with no warning.
Diffstat (limited to 'numpy/lib/polynomial.py')
-rw-r--r-- | numpy/lib/polynomial.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index c0a1cdaed..741cbfa6a 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -599,6 +599,9 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): # it is included here because the covariance of Multivariate Student-T # (which is implied by a Bayesian uncertainty analysis) includes it. # Plus, it gives a slightly more conservative estimate of uncertainty. + if (len(x) - order - 2.0) < 1: + raise ValueError("the number of data points must exceed " + "the degree + 3 for covariance matrix") fac = resids / (len(x) - order - 2.0) if y.ndim == 1: return c, Vbase * fac |