-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Change Rational's round method default rounding from away to even #35756
Conversation
Change round default along with examples.
|
Concerning your second point, I agree consistency would be much better. I will have a look at it to see if I detect any potential issue in doing this. Concerning deprecation, any clue/examples as to how to handle it in this case? I have only seen "whole functions" being deprecated, but here the goal would be to indicate that only one default argument will change in the future, right? |
I would do something like
|
I have made an attempt with the solution using deprecation, and also stated more clearly in the documentation for number field elements that the rounding mode relies on the default one for rationals. There are still some doctests that are impacted and should be fixed, essentially with a lot of copy-pasting of the deprecation warning. So, I would appreciate some feedback on the current changes before doing these fixes. |
The changes look good to me. However, I don't understand why there are doctests that need to contain the deprecation warning in their output. Wouldn't it be possible to specify an explicit rounding mode in the corresponding calls instead? |
This is possible for some of the doctests, but not all (and in fact, not many of those that fail). What I mean is that the call to rationals' Consider for example the following test, in
There is no |
I see. Perhaps we could issue the warning only when there is indeed an ambiguity, or have some way ( |
…plicitly in cusps.py to avoid deprecation warnings in many tests
Good point, yes, there is no reason to raise the warning when round is called in cases where the behaviour has not changed. I have modified this. For the failing doctests, I have specified the rounding mode (to "away" which is the default) in a place which seemed to be responsible for most cases of failures. Let's see if that fixes all of them. |
Documentation preview for this PR (built with commit 07a90a9; changes) is ready! 🎉 |
Confirmed, tests all go fine now. In short: the problem was only that the deprecation warning was appearing here and there; now the warning is only issued in case of ties, and the few remaining warnings in doctests disappear thanks to a single change in a file (making the rounding mode explicit instead of the default). |
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.
Thanks Vincent!
In the code of my package, I now have few deprecation warnings which I tried to fix today. The deprecation is obtained by the following easy example:
Ok, but then how should one fix that warning?
Also notice that for most types, there is no argument
|
I have not encountered this situation before, so I'd be interested to hear about other's solutions/opinions. In any case you should be able to filter these warnings out with something like:
(https://docs.python.org/3/library/warnings.html) Interestingly, |
📚 Description
Fixes #35473. Changes the default of the RationalNumber's round() from away to even. This follows up on #35474 : the commits in the latter are all contained here, and one additional commit is added to fix the testing error and improve the documentation.
📝 Checklist