Skip to content

Commit ac48683

Browse files
committed
Complain when p_signal has low bit depth so that saving works reliably.
1 parent a629039 commit ac48683

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

wfdb/io/record.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ def check_field(self, field, required_channels="all"):
405405
parent_class=(
406406
lambda f: np.integer if f == "d_signal" else np.floating
407407
)(field),
408+
min_itemsize=8 if field == "p_signal" else None,
408409
)
409410
elif field in ["e_d_signal", "e_p_signal"]:
410411
for ch in range(len(item)):
@@ -418,6 +419,7 @@ def check_field(self, field, required_channels="all"):
418419
)
419420
)(field),
420421
channel_num=ch,
422+
min_itemsize=8 if field == "e_p_signal" else None,
421423
)
422424

423425
# Record specification fields
@@ -1745,7 +1747,9 @@ def _check_item_type(
17451747
)
17461748

17471749

1748-
def check_np_array(item, field_name, ndim, parent_class, channel_num=None):
1750+
def check_np_array(
1751+
item, field_name, ndim, parent_class, min_itemsize=None, channel_num=None
1752+
):
17491753
"""
17501754
Check a numpy array's shape and dtype against required
17511755
specifications.
@@ -1786,6 +1790,15 @@ def check_np_array(item, field_name, ndim, parent_class, channel_num=None):
17861790
error_msg = ("Channel %d of f" % channel_num) + error_msg[1:]
17871791
raise TypeError(error_msg)
17881792

1793+
if min_itemsize is not None and item.dtype.itemsize < min_itemsize:
1794+
error_msg = "Field `%s` must have a dtype itemsize of at least %d" % (
1795+
field_name,
1796+
min_itemsize,
1797+
)
1798+
if channel_num is not None:
1799+
error_msg = ("Channel %d of f" % channel_num) + error_msg[1:]
1800+
raise TypeError(error_msg)
1801+
17891802

17901803
# ------------------------- Reading Records --------------------------- #
17911804

0 commit comments

Comments
 (0)