Skip to content

Commit 7bc468b

Browse files
committed
add wfdb.io.wrsamp signal checks
1 parent 1e93bee commit 7bc468b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

wfdb/io/record.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,9 +2933,15 @@ def wrsamp(
29332933
raise Exception(
29342934
"When using d_signal or e_d_signal, must also specify 'fmt', 'gain', and 'baseline' fields"
29352935
)
2936+
if (e_p_signal is not None or e_d_signal is not None) and samps_per_frame is None:
2937+
raise Exception(
2938+
"When passing e_p_signal or e_d_signal, you also need to specify samples per frame for each channel"
2939+
)
29362940

2937-
# If samps_per_frame is a list, check that it aligns as expected with the channels in the signal
2938-
if isinstance(samps_per_frame, list):
2941+
# If samps_per_frame is provided, check that it aligns as expected with the channels in the signal
2942+
if samps_per_frame:
2943+
# Get the number of elements being passed in samps_per_frame
2944+
samps_per_frame_length = len(samps_per_frame) if isinstance(samps_per_frame, list) else 1
29392945
# Get properties of the signal being passed
29402946
first_valid_signal = next(
29412947
signal for signal in signal_list if signal is not None
@@ -2952,13 +2958,11 @@ def wrsamp(
29522958
raise TypeError(
29532959
"Unsupported signal format. Must be ndarray or list of lists."
29542960
)
2955-
29562961
# Check that the number of channels matches the number of samps_per_frame entries
2957-
if num_sig_channels != len(samps_per_frame):
2962+
if num_sig_channels != samps_per_frame_length:
29582963
raise Exception(
2959-
"When passing samps_per_frame as a list, it must have the same number of entries as the signal has channels"
2964+
"When passing samps_per_frame, it must have the same number of entries as the signal has channels"
29602965
)
2961-
29622966
# Check that the number of frames is the same across all channels
29632967
frames = [a / b for a, b in zip(channel_samples, samps_per_frame)]
29642968
if len(set(frames)) > 1:

0 commit comments

Comments
 (0)