Skip to content

Refactor .format to f-string in _percentile.py#6323

Merged
nabenabe0928 merged 2 commits intooptuna:masterfrom
Jongwan93:format-to-fstring-_percentile.py
Oct 30, 2025
Merged

Refactor .format to f-string in _percentile.py#6323
nabenabe0928 merged 2 commits intooptuna:masterfrom
Jongwan93:format-to-fstring-_percentile.py

Conversation

@Jongwan93
Copy link
Copy Markdown
Contributor

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

  • Replaced .format() calls with f-strings in PercentilePruner.__init__ parameter validation.
  • percentile validation
  • n_startup_trials validation
  • n_warmup_steps validation
  • interval_steps validation
  • n_min_trials validation

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}."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=}."

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}."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=}."

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}."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=}."

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}."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=}."

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}."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=}."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new commit with suggestion submitted

@nabenabe0928 nabenabe0928 changed the title refactor .format to fstring in _percentile.py Refactor .format to f-string in _percentile.py Oct 30, 2025
@nabenabe0928 nabenabe0928 changed the title Refactor .format to f-string in _percentile.py Refactor .format to f-string in _percentile.py Oct 30, 2025
Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nabenabe0928 nabenabe0928 added this to the v4.6.0 milestone Oct 30, 2025
@nabenabe0928 nabenabe0928 added the code-fix Change that does not change the behavior, such as code refactoring. label Oct 30, 2025
@nabenabe0928 nabenabe0928 merged commit 0765893 into optuna:master Oct 30, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants