Skip to content

Raise ValueError for digital reads that cannot fit the requested resolution #782

Done

Description

@tompollard

Requesting a digital output dtype too narrow for the source values raises a bare Exception rather than a specific error type:

import wfdb

wfdb.read_record("sample-data/100", kind="digital", resolution=8, stop=10)

This raises Exception: Cannot convert digital samples to lower dtype. Risk of overflow/underflow. The same path is used by rdrecord(..., physical=False, return_res=8) and read_signal_values(..., kind="digital", resolution=8, layout="uniform"). The raises are in convert_dtype in src/wfdb/io/_signal.py.

This is an invalid requested resolution, so ValueError would let callers catch it without catching every exception. Add regression coverage for both uniform and expanded conversions. Found while reviewing #781; it is separate from that PR's naming changes.

Activity

  1. added a commit that references this issue on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions