-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(core): various fixes for latest mpmath changes #25290
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
Conversation
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Is it the changes here compatible with previous mpmath versions (<1.3)? |
I think so. CI runs here with 1.3. These changes are needed for compatibility with the next release of mpmath (1.4?). The changes here mostly reduce dependence on mpmath. They are basically:
I tried running core and polys tests with mpmath 1.2.1 and also mpmath 0.19 which is apparently the minimum version: Line 37 in ad95bcc
There were no test failures. |
I think this looks good! |
@@ -1021,6 +1021,8 @@ class Float(Number): | |||
|
|||
is_Float = True | |||
|
|||
_remove_non_digits = str.maketrans(dict.fromkeys("-+_.")) |
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.
Should this include eE
for exponential notation, too? or maybe better,
if num.startswith('_') or not num.translate(cls._remove_non_digits)
could be
if num.startswith('_') or not all(_.translate(cls._remove_non_digits) for _ in num.lower().split('e'))
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.
It could be. I was just checking for things that the new from_str
in mpmath accepts that were previously not accepted:
In [7]: from mpmath.libmp import from_str
In [8]: from_str("_1", 10)
Out[8]: (0, 1, 0, 1)
In [9]: from_str("e1", 10)
---------------------------------------------------------------------------
ValueError
Feel free to push a more comprehensive test.
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.
Which version allows In[8] to succeed? With 1.3.0 it fails (as I hope it should, since underscore is used to separate digits and if it is present without a bounding digit on each side it could be an entry error):
>>> from mpmath.libmp import from_str
>>> from_str('_1',10)
Traceback (most recent call last):
...
ValueError: could not convert string to float: '_1'
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.
@oscarbenjamin , the question above was my only remaining question before committing this. An underscore prefaced number should not be translated as a number since this is a valid python identifier. SymPy (with this PR) will no loger allow a terminal underscore on a number since this is ambiguous: underscores should come between digits.
see https://stackoverflow.com/a/76915506/1089161 for doc of python math potential bug
I separated out the length function to a new addition to ntheory. |
I've added the 1.13 milestone. We definitely need to get this in before the next release and especially before the next release of mpmath (no idea when that will be). |
@oscarbenjamin , maybe check in on the test suite if this fails. There is a test that is timing out and I don't think it's hitting anything that I have changed. /c |
@smichr you made the changes here far too complicated for me to be able to backport to 1.12.1 in gh-25859. What should have been a relatively simple PR here got turned into a big mess with a lot of changes everywhere including depending on gh-25534. I'm just going to backport my original commit eef227f. If there is some problem with just using the commit then what is/was needed is a simple fix rather than a 50 file refactor. |
sympy/core/numbers.py
Outdated
def sympify_mpmath_mpq(x): | ||
p, q = x._mpq_ | ||
return Rational(p, q, 1) | ||
|
||
_sympy_converter[type(mpmath.rational.mpq(1, 2))] = sympify_mpmath_mpq |
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.
Somehow this got removed from the PR defeating the original purpose of compatibility with mpmath.
References to other Issues or PRs
mpmath/mpmath#704
Brief description of what is fixed or changed
Other comments
Release Notes
<=1.12
may be incompatible with mpmath versions>1.3
.