Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,41 @@ def test_xqrs(self):

assert comparitor.sensitivity > 0.99
assert comparitor.positive_predictivity > 0.99

pass


# Module-level tests for empty-annotation edge cases (pytest collects these
# directly, unlike the lowercase class above which is skipped by default).

def test_compare_annotations_empty_ref():
"""When reference annotations are empty, sensitivity should be NaN."""
import math

comparitor = processing.compare_annotations(
np.array([]), np.array([10, 20, 30]), 5
)
assert math.isnan(comparitor.sensitivity)
assert comparitor.positive_predictivity == 0.0


def test_compare_annotations_empty_test():
"""When test annotations are empty, PPV should be NaN."""
import math

comparitor = processing.compare_annotations(
np.array([10, 20, 30]), np.array([]), 5
)
assert comparitor.sensitivity == 0.0
assert math.isnan(comparitor.positive_predictivity)


def test_compare_annotations_both_empty():
"""When both annotation arrays are empty, both metrics should be NaN."""
import math

comparitor = processing.compare_annotations(
np.array([]), np.array([]), 5
)
assert math.isnan(comparitor.sensitivity)
assert math.isnan(comparitor.positive_predictivity)
7 changes: 5 additions & 2 deletions wfdb/processing/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ def _calc_stats(self):
self.fn = self.n_ref - self.tp
# No tn attribute

self.sensitivity = float(self.tp) / float(self.tp + self.fn)
self.positive_predictivity = float(self.tp) / self.n_test
denom_sens = self.tp + self.fn
self.sensitivity = float(self.tp) / denom_sens if denom_sens > 0 else float("nan")
self.positive_predictivity = (
float(self.tp) / self.n_test if self.n_test > 0 else float("nan")
)

def compare(self):
"""
Expand Down