Skip to content

Reject negative infinity in expanded signals in calc_adc_params - #630

Open
tompollard wants to merge 1 commit into
mainfrom
fix-neg-inf-adc-check
Open

tompollard wants to merge 1 commit into
mainfrom
fix-neg-inf-adc-check

Conversation

@tompollard

Copy link
Copy Markdown
Member

calc_adc_params checks for infinite values before computing the ADC gain and baseline. For p_signal this uses np.isinf, but for e_p_signal it only compared each channel's minimum and maximum against math.inf. A channel containing -inf got past the check and failed later with a misleading error:

import numpy as np, wfdb
wfdb.Record(e_p_signal=[np.array([-np.inf, 1.0])], fmt=["16"]).calc_adc_params()
# ValueError: cannot convert float NaN to integer

It now uses math.isinf, so -inf raises "Signal contains inf. Cannot perform adc." like the p_signal branch.

Testing:

  • New TestSignal.test_adc_params_inf covers +inf and -inf in both p_signal and e_p_signal. The -inf / e_p_signal case fails on main and passes with this change.
  • uv run pytest -m "not network": 349 passed.
  • ruff format --check and ruff check pass. Changelog entry added in changelog.d/.

The inf check for e_p_signal only compared the channel minimum and
maximum against math.inf, so a channel containing -inf got past it and
failed later with "cannot convert float NaN to integer". Use math.isinf
so both signs are caught, as the p_signal branch already does.
@tompollard
tompollard requested a review from briangow November 8, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant