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
sets: made Rationals.contains(float) indeterminate #20565
Conversation
…rminate Currently, sympy.Rationals.contains(0.5) evaluates to False. This patch instead evaluates the expression to indeterminate based on the following logic: a float represents an approximation of an underlying number that could be either rational or irrational. In relation with this change, I have also adjusted a test case that currently asserts sympy.Rationals.contains(1.0) evaluates to False. This test was changed to assert that the expression above evaluates to indeterminate instead of False or True.
✅ Hi, I am the SymPy bot (v161). 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.8. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Travis build failed for transient reason, so re-doing pull request as suggested in chat. |
Codecov Report
@@ Coverage Diff @@
## master #20565 +/- ##
=============================================
+ Coverage 75.741% 75.772% +0.031%
=============================================
Files 673 673
Lines 174499 174497 -2
Branches 41205 41204 -1
=============================================
+ Hits 132168 132221 +53
+ Misses 36611 36561 -50
+ Partials 5720 5715 -5 |
sympy/sets/tests/test_fancysets.py
Outdated
@@ -1046,7 +1046,8 @@ def test_Rationals(): | |||
Rational(1, 3), 3, Rational(-1, 3), -3, Rational(2, 3)] | |||
assert Basic() not in S.Rationals | |||
assert S.Half in S.Rationals | |||
assert 1.0 not in S.Rationals | |||
assert S.Rationals.contains(0.5) is not True | |||
assert S.Rationals.contains(0.5) is not False |
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 would be better to do:
assert Rationals.contains(0.5) == Contains(0.5, Rationals, evaluate=False)
Previously, the test was checking whether Rationals.contains(0.5) was neither false or true. Now, I've adjusted it slightly to more clearly evaluate whether Rationals.contains is indeterminate.
Closing and reopening to restart the tests. |
This looks good. Thanks for the contribution! |
Currently, sympy.Rationals.contains(0.5) evaluates to False.
This patch instead evaluates the expression to indeterminate
based on the following logic: a float represents an approximation
of an underlying number that could be either rational or irrational.
In relation with this change, I have also adjusted a test case
that currently asserts sympy.Rationals.contains(1.0) evaluates
to False. This test was changed to assert that the expression
above evaluates to indeterminate instead of False or True.
Fixes #20364
Current master behavior:
In [1]: sympy.Rationals.contains(0.5)
Patched behavior:
In [1]: sympy.Rationals.contains(0.5)
References to other Issues or PRs
Brief description of what is fixed or changed
Other comments
Release Notes