Skip to content

Commit 310330b

Browse files
author
Benjamin Moody
committed
wr_dat_file: do not modify contents of the d_signal argument.
When writing to an output file, it may be necessary to transform the data in various ways, which is often most efficient to do by modifying the array in-place. However, for API cleanliness, the wr_dat_file function shouldn't modify its argument. Instead, the function itself should make a copy of the array if necessary. (In the future, we may ultimately be able to avoid a copy if the array is already in the correct format.)
1 parent b1c3284 commit 310330b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

wfdb/io/_signal.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,7 @@ def wr_dat_files(self, expanded=False, write_dir=""):
954954
write_dir=write_dir,
955955
)
956956
else:
957-
# Create a copy to prevent overwrite
958-
dsig = self.d_signal.copy()
957+
dsig = self.d_signal
959958
for fn in file_names:
960959
wr_dat_file(
961960
fn,
@@ -2301,6 +2300,9 @@ def wr_dat_file(
23012300
for framenum in range(spf):
23022301
d_signal[:, expand_ch] = e_d_signal[ch][framenum::spf]
23032302
expand_ch = expand_ch + 1
2303+
else:
2304+
# Create a copy to prevent overwrite
2305+
d_signal = d_signal.copy()
23042306

23052307
# This n_sig is used for making list items.
23062308
# Does not necessarily represent number of signals (ie. for expanded=True)

0 commit comments

Comments
 (0)