Repository navigation
Commit cc9f94f
authored
Handle all-NaN channels in calc_adc_params (#628)
Fixes #485.
Writing a record where one channel is entirely NaN fails:
```python
import numpy as np, wfdb
wfdb.wrsamp("xxx", fs=500, units=["mV"], sig_name=["I"],
p_signal=np.array([[np.nan], [np.nan]]), fmt=["16"])
# RuntimeWarning: All-NaN slice encountered (x2)
# ValueError: cannot convert float NaN to integer
```
Both causes are the ones described in the issue:
- `calc_adc_gain_baseline` checked `pmin == np.nan`, which is always
False, so the all-NaN branch never ran. It now uses `np.isnan(pmin)`.
- `calc_adc_params` used `np.nanmin`/`np.nanmax`, which warn on all-NaN
channels. It now uses `np.fmin.reduce`/`np.fmax.reduce` (as suggested in
the issue), which give the same result without the warning, for both
`p_signal` and `e_p_signal`.
An all-NaN channel now gets `adc_gain=1`, `baseline=1` (the existing
intent of that branch), is written as the NaN sample value, and reads
back as NaN.
Testing:
- New `TestSignal.test_all_nan_channel` (runs with RuntimeWarning as an
error): checks `calc_adc_params` for `p_signal` and `e_p_signal`, then a
`wrsamp`/`rdrecord` round trip with one all-NaN channel and one normal
channel. It fails on `main` and passes with this change.
- `uv run pytest -m "not network"`: 335 passed.
- `ruff format --check`, `ruff check` and `towncrier build --draft`
pass. Changelog entry added in `changelog.d/`.3 files changed
Lines changed: 43 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
750 | | - | |
| 750 | + | |
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
831 | | - | |
832 | | - | |
833 | | - | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
834 | 835 | | |
835 | 836 | | |
836 | 837 | | |
| |||
842 | 843 | | |
843 | 844 | | |
844 | 845 | | |
845 | | - | |
846 | | - | |
| 846 | + | |
| 847 | + | |
847 | 848 | | |
848 | 849 | | |
849 | 850 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1615 | 1615 | | |
1616 | 1616 | | |
1617 | 1617 | | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
1618 | 1652 | | |
1619 | 1653 | | |
1620 | 1654 | | |
| |||
0 commit comments