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
2 changes: 2 additions & 0 deletions changelog.d/adc-negative-inf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**Reject negative infinity in expanded signals**
``calc_adc_params`` now raises "Signal contains inf" when ``e_p_signal`` contains ``-inf``, as it already did for ``p_signal``, instead of failing with ``cannot convert float NaN to integer``.
4 changes: 1 addition & 3 deletions src/wfdb/io/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,7 @@ def calc_adc_params(self):
minvals.append(float(np.nanmin(ch)))
maxvals.append(float(np.nanmax(ch)))

if any(x == math.inf for x in minvals) or any(
x == math.inf for x in maxvals
):
if any(math.isinf(x) for x in minvals + maxvals):
raise ValueError("Signal contains inf. Cannot perform adc.")

for ch, _ in enumerate(self.e_p_signal):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,19 @@ def test_physical_conversion(self, temp_path):
atol=(0.05 / gain),
)

@pytest.mark.parametrize("value", [np.inf, -np.inf])
@pytest.mark.parametrize("expanded", [False, True])
def test_adc_params_inf(self, value, expanded):
"""Reject signals containing positive or negative infinity."""
p_signal = np.array([[1.0, 0.5], [value, -0.25]])
if expanded:
record = wfdb.Record(e_p_signal=list(p_signal.T), fmt=["16", "16"])
else:
record = wfdb.Record(p_signal=p_signal, fmt=["16", "16"])

with pytest.raises(ValueError, match="Signal contains inf"):
record.calc_adc_params()

def test_adc_gain_max_boundary(self, temp_path):
"""Exercise the MAX_I32 clamp path.

Expand Down
Loading