summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-03-21 17:20:17 -0600
committerGitHub <noreply@github.com>2017-03-21 17:20:17 -0600
commit88ef1a6ac0e8df043b044f0aa37bf4b2f18c237e (patch)
tree193352aee3e8614e42b714af7fc7cc032a653bd3 /numpy/lib
parent0dd7ca5d57f216d14f70c28694a15fb909ee645e (diff)
parent3c4f17b7d6d44b3076be9d50e305ed71836fa5d9 (diff)
downloadnumpy-88ef1a6ac0e8df043b044f0aa37bf4b2f18c237e.tar.gz
Merge pull request #8807 from eric-wieser/poly1d-fixes-fixes-fixes
TST: Prove that poly1d coeffs are immutable
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/polynomial.py5
-rw-r--r--numpy/lib/tests/test_polynomial.py14
2 files changed, 16 insertions, 3 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index e18bbc8bc..f49b7e295 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -1040,7 +1040,7 @@ class poly1d(object):
@property
def coeffs(self):
- """ The polynomial coefficients """
+ """ A copy of the polynomial coefficients """
return self._coeffs.copy()
@property
@@ -1060,8 +1060,7 @@ class poly1d(object):
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.
+ # scipy to work correctly.
@property
def _coeffs(self):
return self.__dict__['coeffs']
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index f1e4543bb..0725c186d 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -222,6 +222,20 @@ class TestDocs(TestCase):
assert_equal(p == p2, False)
assert_equal(p != p2, True)
+ def test_poly_coeffs_immutable(self):
+ """ Coefficients should not 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[2] += 10
+ assert_equal(p.coeffs, [1, 2, 3])
+
if __name__ == "__main__":
run_module_suite()