Skip to content

Commit 211329c

Browse files
author
Benjamin Moody
committed
wr_dat_file: sanity-check samps_per_frame and e_d_signal.
If expanded is true, then e_d_signal and samps_per_frame must have the same length (one entry in e_d_signal corresponds to one entry in samps_per_frame). The length of each channel must be a multiple of the number of samples per frame, and every channel must have the same number of frames. Add sanity checks to verify that the values provided by the caller make sense.
1 parent 132d097 commit 211329c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

wfdb/io/_signal.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,14 @@ def wr_dat_file(
22882288
# Combine list of arrays into single array
22892289
if expanded:
22902290
n_sig = len(e_d_signal)
2291-
sig_len = int(len(e_d_signal[0]) / samps_per_frame[0])
2291+
if len(samps_per_frame) != n_sig:
2292+
raise ValueError("mismatch between samps_per_frame and e_d_signal")
2293+
2294+
sig_len = len(e_d_signal[0]) // samps_per_frame[0]
2295+
for sig, spf in zip(e_d_signal, samps_per_frame):
2296+
if len(sig) != sig_len * spf:
2297+
raise ValueError("mismatch in lengths of expanded signals")
2298+
22922299
# Effectively create MxN signal, with extra frame samples acting
22932300
# like extra channels
22942301
d_signal = np.zeros((sig_len, sum(samps_per_frame)), dtype="int64")

0 commit comments

Comments
 (0)