Repository navigation
Check that QRS indices are increasing in compute_hr - #603
Merged
tompollard merged 2 commits intoOct 31, 2026
Merged
Conversation
Repeated beats gave a ZeroDivisionError (or inf for NumPy arrays), and beats out of order gave a negative heart rate. Raise a ValueError naming the first pair that is not increasing. Fixes #602.
TheNetherWatcher
force-pushed
the
compute-hr-check-order
branch
from
October 31, 2026 17:23
085a276 to
a07bb68
Compare
Contributor
Author
|
Rebased onto |
tompollard
reviewed
Oct 31, 2026
tompollard
left a comment
Member
There was a problem hiding this comment.
Thanks, this looks good! The error message naming the first bad pair is helpful.
One small suggestion: np.diff wraps around for unsigned integer arrays, so out-of-order beats aren't caught there. For example, np.array([2, 8, 5], dtype=np.uint32) passes the check and gives a meaningless heart rate. Comparing neighbours directly avoids this:
q = np.asarray(qrs_inds)
not_increasing = np.flatnonzero(q[1:] <= q[:-1])Unsigned beat indices are unusual, so I'm happy to merge either way.
tompollard
approved these changes
Oct 31, 2026
np.diff wraps around for unsigned integers, so decreasing unsigned indices weren't caught.
Contributor
Author
|
Good catch, thanks! I've switched to comparing neighbours directly, as you suggested, and added a test with |
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.
Fixes #602.
compute_hrnow raises aValueErrorifqrs_indsis not strictly increasing, naming the first pair that isn't, for example:Before, repeated beats gave a
ZeroDivisionError(lists) orinfwith aRuntimeWarning(arrays), and beats out of order gave a negative heart rate. The docstring now says the indices must be strictly increasing and documents the error.Tests: repeated, decreasing and repeated-last-beat inputs (lists and arrays) raise the error.
pytest -m "not network"passes (103 tests), and the docs build passes.