Skip to content

Raise ValueError for unsupported digital read resolution - #788

Merged
tompollard merged 1 commit into
mainfrom
fix/digital-resolution-error
Nov 30, 2026
Merged

tompollard merged 1 commit into
mainfrom
fix/digital-resolution-error

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Fixes #782.

Raise ValueError instead of a bare Exception when 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 through rdrecord, read_record, and read_signal_values.

Verification

  • Added regression tests for uniform and expanded reads through both new reader functions, and updated the existing expanded rdrecord test to require ValueError.
  • Full offline suite: 1,149 passed, 4 skipped, 22 network tests deselected.
  • Ruff check and format pass.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=8 reads a format 80 record as int8, 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=16 reads as int16.

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".

@tompollard

Copy link
Copy Markdown
Member Author

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.

@tompollard
tompollard merged commit 1bc5f73 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the fix/digital-resolution-error branch November 30, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise ValueError for digital reads that cannot fit the requested resolution

1 participant