Skip to content

Commit bd3bedd

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

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

wfdb/io/record.py

Lines changed: 12 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,7 @@ 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(item, field_name, ndim, parent_class, min_itemsize=None, channel_num=None):
17491751
"""
17501752
Check a numpy array's shape and dtype against required
17511753
specifications.
@@ -1786,6 +1788,15 @@ def check_np_array(item, field_name, ndim, parent_class, channel_num=None):
17861788
error_msg = ("Channel %d of f" % channel_num) + error_msg[1:]
17871789
raise TypeError(error_msg)
17881790

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

17901801
# ------------------------- Reading Records --------------------------- #
17911802

0 commit comments

Comments
 (0)