Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: deep copying polybase broken #22669

Closed
ncsaba opened this issue Nov 24, 2022 · 1 comment
Closed

BUG: deep copying polybase broken #22669

ncsaba opened this issue Nov 24, 2022 · 1 comment

Comments

@ncsaba
Copy link

ncsaba commented Nov 24, 2022

Describe the issue:

The issue is at line 502 in _polybase.py:
ret['symbol'] = self.symbol.copy()

Pronblem is that self.symbol is a string and has no copy method. Instead should be assigned directly as it is immutable:

ret['symbol'] = self.symbol

Reproduce the code example:

>>> from numpy.polynomial import Polynomial
>>> x = Polynomial([1, 2, 3])
>>> from copy import deepcopy
>>> deepcopy(x)

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/copy.py", line 161, in deepcopy
    rv = reductor(4)
  File "/hdd/tmp/tempvenv/lib/python3.8/site-packages/numpy/polynomial/_polybase.py", line 502, in __getstate__
    ret['symbol'] = self.symbol.copy()
AttributeError: 'str' object has no attribute 'copy'

NumPy/Python version information:

1.24.0rc1 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0]

Context for the issue:

Easy fix in the bug description.

@ncsaba ncsaba changed the title BUG: copying polybase broken BUG: deep copying polybase broken Nov 24, 2022
MatteoRaso added a commit to MatteoRaso/numpy that referenced this issue Nov 25, 2022
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.
@seberg seberg added this to the 1.24.0 release milestone Nov 25, 2022
mattip added a commit that referenced this issue Nov 27, 2022
BUG: Polynomials now copy properly (#22669)
@MatteoRaso
Copy link
Contributor

Bug has been fixed.

@bsipocz bsipocz closed this as completed Nov 28, 2022
charris pushed a commit to charris/numpy that referenced this issue Dec 22, 2022
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.
charris added a commit that referenced this issue Dec 22, 2022
BUG: Polynomials now copy properly (#22669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants