summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Raso <matteo_luigi_raso@protonmail.com>2022-11-25 00:28:35 -0500
committerMatteo Raso <matteo_luigi_raso@protonmail.com>2022-11-25 00:28:35 -0500
commit3b9c49e5bb47a979fedb151e36f4e3a00724b096 (patch)
tree97db8178d308d4ad1aeff776951920d8631d2ece
parent6aacc5167983d7c6f8689d7039294f2fc0d5f5fb (diff)
downloadnumpy-3b9c49e5bb47a979fedb151e36f4e3a00724b096.tar.gz
BUG: Polynomials now copy properly (#22669)
On line 502, self.symbol.copy() was called, which causes an AttributeError, since self.symbol is a string, so it doesn't have a copy() method. To fix it, I simply removed the copy() and directly assigned the string.
-rw-r--r--numpy/polynomial/_polybase.py2
-rw-r--r--numpy/polynomial/tests/test_polynomial.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py
index 9674dee0b..3bea91dd2 100644
--- a/numpy/polynomial/_polybase.py
+++ b/numpy/polynomial/_polybase.py
@@ -499,7 +499,7 @@ class ABCPolyBase(abc.ABC):
ret['coef'] = self.coef.copy()
ret['domain'] = self.domain.copy()
ret['window'] = self.window.copy()
- ret['symbol'] = self.symbol.copy()
+ ret['symbol'] = self.symbol
return ret
def __setstate__(self, dict):
diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py
index a0a09fcf4..032bf0e76 100644
--- a/numpy/polynomial/tests/test_polynomial.py
+++ b/numpy/polynomial/tests/test_polynomial.py
@@ -5,6 +5,7 @@ from functools import reduce
import numpy as np
import numpy.polynomial.polynomial as poly
+from copy import deepcopy
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
assert_warns, assert_array_equal, assert_raises_regex)
@@ -41,6 +42,10 @@ class TestConstants:
def test_polyx(self):
assert_equal(poly.polyx, [0, 1])
+ def test_copy(self):
+ x = poly.Polynomial([1, 2, 3])
+ y = deepcopy(x)
+ assert_equal(x, y)
class TestArithmetic: