From ef6559dd63af3f6140c2011d3c02b4628c6fa766 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 16 Mar 2017 01:07:35 +0000 Subject: BUG: Fix regression in scipy that relied on quirky behaviour Scipy needs `.__dict__['coeffs']` to work, so we can't call the member _coeffs --- numpy/lib/polynomial.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'numpy/lib/polynomial.py') diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index 50e6d8db2..ddff0d3b0 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -1059,6 +1059,16 @@ class poly1d(object): """ The roots of the polynomial, where self(x) == 0 """ return roots(self._coeffs) + # our internal _coeffs property need to be backed by __dict__['coeffs'] for + # scipy to work correctly. Note that as a result, the getter for .coeffs + # does not run unless accessed through one of its aliases. + @property + def _coeffs(self): + return self.__dict__['coeffs'] + @_coeffs.setter + def _coeffs(self, coeffs): + self.__dict__['coeffs'] = coeffs + # alias attributes r = roots c = coef = coefficients = coeffs -- cgit v1.2.1 From 0ea21d1092c9154d72d50b04ba2c8025704c679f Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 21 Mar 2017 21:05:56 +0000 Subject: BUG: Prevent modification of coefficients `poly.coeffs = 1` has always failed with a strong exception guarantee. However, `poly.coeffs += 1` would both change the state and fail. Now both fail without affecting the value. --- numpy/lib/polynomial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/polynomial.py') diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index ddff0d3b0..e18bbc8bc 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -1041,7 +1041,7 @@ class poly1d(object): @property def coeffs(self): """ The polynomial coefficients """ - return self._coeffs + return self._coeffs.copy() @property def variable(self): -- cgit v1.2.1