Skip to content

Complain when p_signal has low bit depth so that saving works reliably #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion wfdb/io/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def check_field(self, field, required_channels="all"):
parent_class=(
lambda f: np.integer if f == "d_signal" else np.floating
)(field),
min_itemsize=8 if field == "p_signal" else None,
)
elif field in ["e_d_signal", "e_p_signal"]:
for ch in range(len(item)):
Expand All @@ -418,6 +419,7 @@ def check_field(self, field, required_channels="all"):
)
)(field),
channel_num=ch,
min_itemsize=8 if field == "e_p_signal" else None,
)

# Record specification fields
Expand Down Expand Up @@ -1745,7 +1747,9 @@ def _check_item_type(
)


def check_np_array(item, field_name, ndim, parent_class, channel_num=None):
def check_np_array(
item, field_name, ndim, parent_class, min_itemsize=None, channel_num=None
):
"""
Check a numpy array's shape and dtype against required
specifications.
Expand Down Expand Up @@ -1786,6 +1790,15 @@ def check_np_array(item, field_name, ndim, parent_class, channel_num=None):
error_msg = ("Channel %d of f" % channel_num) + error_msg[1:]
raise TypeError(error_msg)

if min_itemsize is not None and item.dtype.itemsize < min_itemsize:
error_msg = "Field `%s` must have a dtype itemsize of at least %d" % (
field_name,
min_itemsize,
)
if channel_num is not None:
error_msg = ("Channel %d of f" % channel_num) + error_msg[1:]
raise TypeError(error_msg)


# ------------------------- Reading Records --------------------------- #

Expand Down
Loading