Refactor .format to f-string in _percentile.py#6323
Merged
nabenabe0928 merged 2 commits intooptuna:masterfrom Oct 30, 2025
Merged
Refactor .format to f-string in _percentile.py#6323nabenabe0928 merged 2 commits intooptuna:masterfrom
.format to f-string in _percentile.py#6323nabenabe0928 merged 2 commits intooptuna:masterfrom
Conversation
optuna/pruners/_percentile.py
Outdated
| if not 0.0 <= percentile <= 100: | ||
| raise ValueError( | ||
| "Percentile must be between 0 and 100 inclusive but got {}.".format(percentile) | ||
| f"Percentile must be between 0 and 100 inclusive but got {percentile}." |
Contributor
There was a problem hiding this comment.
Suggested change
| f"Percentile must be between 0 and 100 inclusive but got {percentile}." | |
| f"Percentile must be between 0 and 100 inclusive, but got {percentile=}." |
optuna/pruners/_percentile.py
Outdated
| if n_startup_trials < 0: | ||
| raise ValueError( | ||
| "Number of startup trials cannot be negative but got {}.".format(n_startup_trials) | ||
| f"Number of startup trials cannot be negative but got {n_startup_trials}." |
Contributor
There was a problem hiding this comment.
Suggested change
| f"Number of startup trials cannot be negative but got {n_startup_trials}." | |
| f"Number of startup trials cannot be negative, but got {n_startup_trials=}." |
optuna/pruners/_percentile.py
Outdated
| if n_warmup_steps < 0: | ||
| raise ValueError( | ||
| "Number of warmup steps cannot be negative but got {}.".format(n_warmup_steps) | ||
| f"Number of warmup steps cannot be negative but got {n_warmup_steps}." |
Contributor
There was a problem hiding this comment.
Suggested change
| f"Number of warmup steps cannot be negative but got {n_warmup_steps}." | |
| f"Number of warmup steps cannot be negative, but got {n_warmup_steps=}." |
optuna/pruners/_percentile.py
Outdated
| if interval_steps < 1: | ||
| raise ValueError( | ||
| "Pruning interval steps must be at least 1 but got {}.".format(interval_steps) | ||
| f"Pruning interval steps must be at least 1 but got {interval_steps}." |
Contributor
There was a problem hiding this comment.
Suggested change
| f"Pruning interval steps must be at least 1 but got {interval_steps}." | |
| f"Pruning interval steps must be at least 1, but got {interval_steps=}." |
optuna/pruners/_percentile.py
Outdated
| if n_min_trials < 1: | ||
| raise ValueError( | ||
| "Number of trials for pruning must be at least 1 but got {}.".format(n_min_trials) | ||
| f"Number of trials for pruning must be at least 1 but got {n_min_trials}." |
Contributor
There was a problem hiding this comment.
Suggested change
| f"Number of trials for pruning must be at least 1 but got {n_min_trials}." | |
| f"Number of trials for pruning must be at least 1, but got {n_min_trials=}." |
Contributor
Author
There was a problem hiding this comment.
new commit with suggestion submitted
.format to f-string in _percentile.py
.format to f-string in _percentile.py.format to f-string in _percentile.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Following the recommendation in #6305, I'm replacing the old-style .format() string formatting with the cleaner f-string syntax.
Description of the changes
.format()calls with f-strings inPercentilePruner.__init__parameter validation.percentilevalidationn_startup_trialsvalidationn_warmup_stepsvalidationinterval_stepsvalidationn_min_trialsvalidation