Skip to content

Commit 7704233

Browse files
author
Benjamin Moody
committed
adc (inplace=True, expanded=False): correctly handle NaNs.
When converting physical to digital sample arrays, we must replace NaN values (which represent a missing sample) with the appropriate invalid-sample sentinel value. This is done correctly for normal uses of the package, but if the application directly invoked adc(inplace=True), NaNs would not have been handled (and were instead set to an implementation-defined value.) (Note that we don't use inplace=True internally because this overwrites the original floating-point array. Applications may want to use inplace=True to save memory, but this requires knowing that the original array is no longer needed.)
1 parent 2eabaa5 commit 7704233

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

wfdb/io/_signal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,12 @@ def adc(self, expanded=False, inplace=False):
562562
np.add(p_signal, self.baseline, p_signal)
563563
np.round(p_signal, 0, p_signal)
564564
d_signal = p_signal.astype(intdtype, copy=False)
565+
566+
if nanlocs.any():
567+
for ch in range(d_signal.shape[1]):
568+
if nanlocs[:, ch].any():
569+
d_signal[nanlocs[:, ch], ch] = d_nans[ch]
570+
565571
self.d_signal = d_signal
566572
self.p_signal = None
567573

0 commit comments

Comments
 (0)