fix: guard against ZeroDivisionError in Comparitor._calc_stats#566
Open
haoyu-haoyu wants to merge 3 commits intoMIT-LCP:mainfrom
Open
fix: guard against ZeroDivisionError in Comparitor._calc_stats#566haoyu-haoyu wants to merge 3 commits intoMIT-LCP:mainfrom
haoyu-haoyu wants to merge 3 commits intoMIT-LCP:mainfrom
Conversation
When there are no reference annotations (tp + fn == 0) or no test annotations (n_test == 0), computing sensitivity and positive predictivity raises ZeroDivisionError. Return NaN instead, matching the convention used by sklearn.metrics for undefined ratios. Fixes MIT-LCP#278
Cover three boundary scenarios that previously raised ZeroDivisionError: - Empty reference, non-empty test → sensitivity=NaN, PPV=0.0 - Non-empty reference, empty test → sensitivity=0.0, PPV=NaN - Both empty → both NaN
The existing test_qrs class uses lowercase naming which pytest's default collection does not pick up. Move the new empty-annotation tests to module level so they are actually discovered and run in CI.
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
Guard against
ZeroDivisionErrorwhen comparing annotations with empty reference or test arrays.Bug
Comparitor._calc_stats()dividestpby(tp + fn)for sensitivity and byn_testfor positive predictivity without checking for zero denominators. When either annotation array is empty, this raisesZeroDivisionError.Fix
Return
float("nan")when the denominator is zero, matching the convention used bysklearn.metricsfor undefined ratios.Tests
Three module-level test functions covering all edge cases:
Fixes #278