Skip to content

Avoid all-NaN warnings when computing percentile reference - #6893

Merged
kAIto47802 merged 2 commits into
optuna:masterfrom
Ganesh1729-ui:fix/median-pruner-nan-warning
Oct 21, 2026
Merged

kAIto47802 merged 2 commits into
optuna:masterfrom
Ganesh1729-ui:fix/median-pruner-nan-warning

Conversation

@Ganesh1729-ui

@Ganesh1729-ui Ganesh1729-ui commented Oct 11, 2026 •

Copy link
Copy Markdown

Summary

Follow-up to #6873 and #6872. The merged fix in #6873 handles all-NaN values within one trial when finding its best intermediate result. A separate path still passes all-NaN values from completed trials to np.nanpercentile, emitting RuntimeWarning: All-NaN slice encountered while returning NaN. I merged current master into this branch and narrowed this PR to that remaining percentile reference calculation.

For a nonempty all-NaN array, the helper now returns NaN before aggregation. The existing test changes from suppressing the warning to treating it as an error. The n_min_trials check and empty-array behavior remain intact. The published diff is two files, six additions and two deletions.

Validation

  • On current master, a direct reproduction emits the warning in both minimize and maximize modes; on this branch it emits none.
  • The affected module passes 11 tests; the full pruner suite passes 97 tests with two unrelated existing UserWarnings.
  • Ruff check and format check pass for both changed files. The earlier 14 green CI checks belonged to the previous head; new-head CI is pending.

AI assisted the implementation and review. I inspected the merged upstream change, resolved the conflicts, and ran the checks above.

@Ganesh1729-ui Ganesh1729-ui changed the title Fix \MedianPruner\ \RuntimeWarning\ leak with all-NaN intermediate values Fix MedianPruner warnings for all-NaN intermediate values Oct 12, 2026
@Ganesh1729-ui

Ganesh1729-ui commented Oct 13, 2026 •

Copy link
Copy Markdown
Author

Update for ed4041fc: #6873 merged while this PR was open and resolved the best-value path from #6872. I merged current master, removed the overlapping change, and kept only the separate all-NaN percentile-reference fix. The PR now has a six-addition/two-deletion diff in two files and is mergeable.

On unchanged current master, that remaining path emits RuntimeWarning: All-NaN slice encountered in both minimize and maximize modes; the updated branch emits none. The affected module passes 11 tests, the pruner suite passes 97 tests (with two unrelated existing UserWarnings), and Ruff check/format pass. The 14 earlier successful CI checks apply to b8b602e9, not this new head. The updated title and description explain the narrowed scope; new-head CI and maintainer review are pending.

@Ganesh1729-ui Ganesh1729-ui changed the title Fix MedianPruner warnings for all-NaN intermediate values Avoid all-NaN warnings when computing percentile reference Oct 13, 2026
@Ganesh1729-ui

Copy link
Copy Markdown
Author

CI update for the current ed4041fc head: all 12 GitHub Actions checks, including the Sphinx documentation and doctest jobs, passed. The remaining failing status is the external Read the Docs build 35114300.

Read the Docs reports “Build terminated due to time out.” Its public build log shows the final Sphinx command starting but no Sphinx exit code or source error before termination. The previous PR-head build and a current master build succeeded. This PR changes only the pruner and its tests; it does not edit documentation.

I have not made a source change for a build that timed out. A retry of the external Read the Docs build would help distinguish a transient timeout from a reproducible problem.

@gen740 gen740 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix looks good to me. I left a few minor suggestions to simplify the implementation and make the warning checks more consistent.

Comment thread optuna/pruners/_percentile.py Resolved
Comment thread tests/pruners_tests/test_percentile.py Resolved
Comment thread tests/pruners_tests/test_percentile.py Resolved

@gen740 gen740 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@c-bata c-bata assigned kAIto47802 and unassigned gen740 Oct 16, 2026
@c-bata

c-bata commented Oct 16, 2026

Copy link
Copy Markdown
Member

@kAIto47802 Could you review this PR?

… values

Fixed by returning NaN directly in _get_best_intermediate_result_over_steps
and _get_percentile_intermediate_result_over_trials when all intermediate
values are NaN, avoiding np.nanmin/np.nanmax and np.nanpercentile
from emitting 'All-NaN slice encountered' warnings.

Updated existing tests to use simplefilter('error') so the leak cannot
regress.

Fixes optuna#6872
@Ganesh1729-ui
Ganesh1729-ui force-pushed the fix/median-pruner-nan-warning branch from 2f6fd2c to e736ecc Compare October 19, 2026 04:35

@kAIto47802 kAIto47802 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@kAIto47802 kAIto47802 added the bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. label Oct 21, 2026
@kAIto47802 kAIto47802 added this to the v5.1.0 milestone Oct 21, 2026
@kAIto47802
kAIto47802 merged commit 4053669 into optuna:master Oct 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants