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
Fix pickling/deepcopying of floats when using gmpy2 backend #13530
Conversation
sympy/core/numbers.py
Outdated
@@ -19,6 +19,7 @@ | |||
SYMPY_INTS, int_info) | |||
import mpmath | |||
import mpmath.libmp as mlib | |||
from mlib.backend import MPZ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is wrong.
If this is based on a fix by @ovolve please keep the original commit metadata so that the authorship is correct. |
I think technically the original author was @casevh in #7457 (comment) |
Or more accurately in #7457 (comment) |
You can cherry-pick commits from #10674 or (re)base the branch on it. |
The patch from @ovolve is a two-line change that doesn't apply cleanly to current master. I don't understand how to preserve that commit metadata for this patch. |
c64e0fd
to
287528e
Compare
Alright, I think I figured it out. The commit history should be more consistent now. |
@asmeurer This is ready for review |
You can also use the original commit and do a git merge to get it up to date with master. |
Any blockers for this? |
sympy/core/numbers.py
Outdated
@@ -29,6 +30,7 @@ | |||
from .evaluate import global_evaluate | |||
|
|||
from sympy.utilities.exceptions import SymPyDeprecationWarning | |||
from mpmath.libmp.backend import MPZ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate import
e3589d2
to
d10cd88
Compare
def test_core_float_copy(): | ||
# See gh-7457 | ||
y = Symbol("x") + 1.0 | ||
copy.deepcopy(y) # does not raise TypeError ("argument is not an mpz") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use check
function like other tests?
21fa473
to
b028acf
Compare
Ready for another look |
LGTM. Edited PR description to auto-close mentioned issues and PRs. Thank you for your contribution! |
Fixes gh-7457, closes gh-10674, and fixes gh-12895.
This is a rebased fix by @ovolve and a minimal test to address a bad interaction with pickling/deepcopying of
Float
objects whengmpy2
is installed (i.e., the "Argument is not an mpz" ValueError). When a future version ofgmpy2
is released to address the underlying issue, this fix should be forward-compatible.cc @asmeurer @casevh