Repository navigation
Raise ValueError for unsupported digital read resolution - #788
Conversation
tompollard
left a comment
There was a problem hiding this comment.
This looks ready to merge. Thanks for fixing #782.
ValueError is a subclass of Exception, so existing except Exception code still works. Only the exception type changes; the check and its message stay the same.
The check rejects only what it should:
resolution=8reads a format 80 record asint8, in both layouts.- It's rejected for format 212 (
sample-data/100) and format 16 (sample-data/a103l). - Format 24 is rejected at
resolution=16. - Format 212 at
resolution=16reads asint16.
Those are the only two places in convert_dtype that raise this error, and the offline suite and ruff pass.
Optional, here or later: the message says "Cannot convert digital samples to lower dtype". Someone calling read_record(..., resolution=8) hasn't asked for a dtype, so naming the argument and the smallest value that works would make the fix obvious. For example: "resolution=8 is too small for format 212 digital samples; use 16 or higher".
|
Thanks for checking these cases. I agree that naming the requested resolution and the minimum supported resolution would make the error more useful. I’d keep this PR focused on the exception type. The diagnostic needs to be accurate for mixed-format records as well as single-format records, so I’d handle that in a separate change. No further code change is needed for #788. |
Summary
Fixes #782.
Raise
ValueErrorinstead of a bareExceptionwhen a requested digital read dtype is too narrow for the source dtype. The rejection logic and message are unchanged. This applies to uniform and expanded reads throughrdrecord,read_record, andread_signal_values.Verification
rdrecordtest to requireValueError.