fix(validation): correct 'and' to 'or' in argument validation across multiple metrics - #3440
Open
AbdullahRasheed45 wants to merge 1 commit into
Open
Conversation
…multiple metrics
Several validation guards used the wrong logical operator ('and' instead
of 'or'), so invalid arguments were silently accepted and caused cryptic
runtime errors rather than a clear ValueError at initialisation time.
Affected metrics and the invalid inputs that bypassed validation:
- BinarySpecificityAtSensitivity / MulticlassSpecificityAtSensitivity
/ MultilabelSpecificityAtSensitivity
(specificity_sensitivity.py): min_sensitivity as an out-of-range float,
e.g. 2.0, was accepted without error.
- BinaryRecallAtFixedPrecision / MulticlassRecallAtFixedPrecision
/ MultilabelRecallAtFixedPrecision
(recall_fixed_precision.py): same bug for min_precision.
- BinarySensitivityAtSpecificity / MulticlassSensitivityAtSpecificity
/ MultilabelSensitivityAtSpecificity
(sensitivity_specificity.py): same bug for min_specificity.
- SpearmanCorrCoef / PearsonCorrCoef / LogCoshError (spearman.py,
pearson.py, log_cosh.py): num_outputs=0 or a negative integer was
accepted without error.
- BinaryFairness / MulticlassFairness (group_fairness.py): num_groups=1
or a negative integer was accepted without error.
- PeakSignalNoiseRatioWithBlockedEffect (psnrb.py): block_size=0 or a
negative integer was accepted without error.
In every case the fix is the same: replace 'and' with 'or' so that an
invalid argument raises ValueError when either type-check or value-check
fails, not only when both fail simultaneously.
AbdullahRasheed45
requested review from
SkafteNicki and
justusschock
as code owners
July 31, 2026 02:17
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.
Summary
Several argument validation guards across multiple metrics used the wrong logical operator ( instead of ). As a result, invalid arguments were silently accepted and caused cryptic runtime errors deep inside the metric computation rather than a clear
ValueErrorat initialisation time.This pattern was first identified in
stat_scores.py(issues #3405, resolved in PRs #3406/#3416) and in retrieval metrics (issue #3378). This PR fixes the identical bug in all remaining affected files.The Bug
The guards follow the pattern:
For an invalid-value-but-correct-type input (e.g.,
min_sensitivity=2.0):not isinstance(2.0, float)→False2.0is outside[0, 1]→TrueFalse and True→False— no error raised!Fix: replace with so validation fails when either the type or the value is wrong.
Files Changed
functional/classification/specificity_sensitivity.py(3 sites)min_sensitivity2.0,-0.5functional/classification/recall_fixed_precision.py(3 sites)min_precision2.0,-0.1functional/classification/sensitivity_specificity.py(3 sites)min_specificity2.0,-0.5regression/spearman.pynum_outputs0, negative integersregression/pearson.pynum_outputs0, negative integersregression/log_cosh.pynum_outputs0, negative integersclassification/group_fairness.py(2 sites)num_groups0,1, negative integersimage/psnrb.pyblock_size0, negative integersMinimal Reproduction