-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Migrate to f-strings in python-package\lightgbm\plotting.py (#4136) #4279
Conversation
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 very much for taking the time to contribute! Please see a few suggestions below.
|
||
|
||
def _float2str(value, precision=None): | ||
return ("{0:.{1}f}".format(value, precision) | ||
return (f"{value:.{precision}f}" |
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.
nice work! Did not know you could do string interpolation on the right-hand side of the :
in an f-string.
I tested a few cases and confirmed that this still has the expected behavior.
assert _float2str(0.0000001) == '1e-07'
assert _float2str(0.0000001, precision=1) == '0.0'
assert _float2str(0.0000001, precision=10) == '0.0000001000'
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.
Yes, even I learnt this today :)
Co-authored-by: James Lamb <jaylamb20@gmail.com>
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.
LGTM!
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Related to #4136