Repository navigation
Fix NaN comparison when skipping enqueued trials - #6803
Merged
c-bata merged 1 commit intoAug 21, 2026
Merged
Conversation
ishitta-iyer
force-pushed
the
fix/enqueue-trial-nan-duplicate
branch
from
August 13, 2026 19:44
e0aae41 to
ba3fcfb
Compare
4 tasks done
gen740
requested changes
Aug 21, 2026
gen740
left a comment
Member
There was a problem hiding this comment.
Good change.
However, I realized that the tests for enqueue_trial are a bit complicated and spread across the code base.
I think this is a good opportunity to introduce a simpler and more comprehensive test like:
@pytest.mark.parametrize("storage_mode", STORAGE_MODES)
@pytest.mark.parametrize(
"params, expected_n_trials",
[
(["foo", "foo"], 1),
([1, 1], 1),
([1.1, 1.1], 1),
([1e17, 1e17], 1),
([1e-17, 1e-17], 1),
([float("inf"), float("inf")], 1),
([float("-inf"), float("-inf")], 1),
([float("nan"), float("nan")], 1),
([None, None], 1),
([0.0, float("nan")], 2),
([float("nan"), 0.0], 2),
],
)
def test_enqueue_trial_skip_existing_handles_values(
storage_mode: str,
params: list[Any],
expected_n_trials: int,
) -> None:
with StorageSupplier(storage_mode) as storage:
study = create_study(storage=storage)
for param in params:
study.enqueue_trial({"x": param}, skip_if_exists=True)
assert len(study.trials) == expected_n_trialsThis test can cover many cases, and we can consolidate the following tests into it:
test_enqueue_trial_skips_existing_waitingtest_enqueue_trial_skip_existing_handles_common_typestest_enqueue_trial_skip_existing_distinguishes_nan_from_numeric_values
gen740
approved these changes
Aug 21, 2026
gen740
left a comment
Member
There was a problem hiding this comment.
I reconsidered my suggestion above. Since this is more of a test refactoring and not directly related to this fix, it would be better handled separately.
The current change looks good. Approving this PR.
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
Fixes #6798.
When
skip_if_exists=True,Study.enqueue_trialincorrectly treats a newly enqueuedNaNas a duplicate of any existing numeric value. This makes duplicate detection asymmetric: enqueueing0.0followed byNaNbehaves differently from enqueueing the same values in reverse order.Description of the changes
Use
np.isclose(..., equal_nan=True)when comparing numeric parameter values.This ensures that:
NaNand ordinary numeric values are distinct.NaNvalues are treated as duplicates.A regression test covers both
0.0followed byNaNandNaNfollowed by0.0across all configured storage modes.Validation
git diff --checkpassed.