summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-07-08 22:39:55 +0200
committerEric Wieser <wieser.eric@gmail.com>2017-07-08 22:39:55 +0200
commit389bd44e32b0eace0d024b126931a0a00d14cffe (patch)
tree3840e374eb3bdf928c26c40689b8b63e525aa804 /numpy/lib
parent3c4f17b7d6d44b3076be9d50e305ed71836fa5d9 (diff)
downloadnumpy-389bd44e32b0eace0d024b126931a0a00d14cffe.tar.gz
BUG: Return the coefficients array directly
Turns out that this was relied upon downstream We also add a setter for coeffs, so that augmented assignment does not both change state and raise an exception suggesting state could not be changed.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/polynomial.py10
-rw-r--r--numpy/lib/tests/test_polynomial.py18
2 files changed, 17 insertions, 11 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index f49b7e295..1b13b38a0 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -1040,8 +1040,14 @@ class poly1d(object):
@property
def coeffs(self):
- """ A copy of the polynomial coefficients """
- return self._coeffs.copy()
+ """ The polynomial coefficients """
+ return self._coeffs
+
+ @coeffs.setter
+ def coeffs(self, value):
+ # allowing this makes p.coeffs *= 2 legal
+ if value is not self._coeffs:
+ raise AttributeError("Cannot set attribute")
@property
def variable(self):
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index 0725c186d..2aed5c924 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -222,19 +222,19 @@ class TestDocs(TestCase):
assert_equal(p == p2, False)
assert_equal(p != p2, True)
- def test_poly_coeffs_immutable(self):
- """ Coefficients should not be modifiable """
+ def test_poly_coeffs_mutable(self):
+ """ Coefficients should be modifiable """
p = np.poly1d([1, 2, 3])
- try:
- # despite throwing an exception, this used to change state
- p.coeffs += 1
- except Exception:
- pass
- assert_equal(p.coeffs, [1, 2, 3])
+ p.coeffs += 1
+ assert_equal(p.coeffs, [2, 3, 4])
p.coeffs[2] += 10
- assert_equal(p.coeffs, [1, 2, 3])
+ assert_equal(p.coeffs, [2, 3, 14])
+
+ # this never used to be allowed - let's not add features to deprecated
+ # APIs
+ assert_raises(AttributeError, setattr, p, 'coeffs', np.array(1))
if __name__ == "__main__":