Repository navigation
Conversation
Add handling for peak index data types to ensure proper arithmetic operations.
This change improves the handling of integer indices in peak correction by widening them to avoid wraparound issues, ensuring compatibility with NumPy indexing.
tompollard
reviewed
Nov 28, 2026
tompollard
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR! I found one case where the new cast silently changes a peak index. np.uint64(2**64 - 1) becomes -1 when cast to np.intp. With a 20-sample signal that has a peak at index 1, correct_peaks(..., peak_dir="up") then returns [1]; the base version raises an error.
Could we reject unsigned values above np.iinfo(np.intp).max before casting? That would prevent an unrepresentable index from becoming a plausible corrected peak without adding general bounds validation.
Check platform integer limits before conversion to avoid uint64 wraparound.
Add nine regression cases for platform index range conversion.
This branch has not been deployed
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.
Problem
processing.correct_peaksaccepts integer index arrays but performs search-window arithmetic in their original dtype. Unsigned indices can wrap near the left boundary, narrow signed/unsigned indices can overflow near the right boundary, anduint64indices combined with signed shifts can produce float results that cannot index NumPy arrays.Change
Normalize array-like guesses with
np.asarray, then widen integer arrays to platform index typenp.intpinsideshift_peaksbefore arithmetic. Valid sample indices are assumed to fitnp.intp. Python integer lists remain accepted; output integer dtype can widen. This does not introduce validation guarantees for invalid/out-of-range indices, bools or floats.Tests cover all four direction modes, six integer dtypes, left/right boundaries, order and duplicates, input nonmutation, usable integer output, a Python-list control and a locally written/read WFDB record. Includes a changelog fragment. This is distinct from the earlier right-window and near-start/order changes in #611, #613 and #680.
Validation
Requalified on current upstream
abfe426a5eadb7130bd6b55978e1324a8ea04a3d, Python 3.12.16, NumPy 2.5.5, SciPy 1.18.1:uv run pytest -q -m 'not network': 957 passed, 4 skipped because the externalbxbutility is absent, 21 network tests deselected.-W --keep-going -E: passed.Only this fix was applied. Network tests, other platforms/dependency versions and remote CI were not run locally. Prepared and tested with AI assistance; no independent human QA, clinical validation or waveform-quality claim is made.