Skip to content

Commit

Permalink
BUG: Polynomials now copy properly (numpy#22669)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MatteoRaso authored and charris committed Dec 22, 2022
1 parent 9bbf8c1 commit 94e405b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/polynomial/_polybase.py
Expand Up @@ -499,7 +499,7 @@ def __getstate__(self):
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):
Expand Down
5 changes: 5 additions & 0 deletions numpy/polynomial/tests/test_polynomial.py
Expand Up @@ -5,6 +5,7 @@

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)
Expand Down Expand Up @@ -41,6 +42,10 @@ def test_polyone(self):
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:

Expand Down

0 comments on commit 94e405b

Please sign in to comment.