Skip to content

Read format 61 signals with smooth_frames=False - #678

Merged
tompollard merged 2 commits into
mainfrom
expanded-dtype-byte-order
Nov 24, 2026
Merged

tompollard merged 2 commits into
mainfrom
expanded-dtype-byte-order

Conversation

@tompollard

Copy link
Copy Markdown
Member

rdrecord with physical=False and smooth_frames=False fails for any record with a format 61 signal:

wfdb.rdrecord("sample-data/p10143", physical=False, smooth_frames=False)
# ValueError: invalid literal for int() with base 10: ''

convert_dtype compared dtypes by parsing their names (int(str(dtype)[3:])). Format 61 is stored in big-endian byte order, so its dtype is >i2, which has nothing after the first three characters. It now uses np.can_cast(current_dtype, return_dtype, "safe"), which handles byte order. Samples are returned in the requested native dtype, and asking for a dtype that is too small still raises the same "lower dtype" error.

This is the read that a lossless round trip needs (#484, #500). It affects p10143 and binformats in sample-data. Writing format 61 is still not supported, so those two records can be read this way but not yet written back.

Testing:

  • New TestExpandedBigEndian checks the samples and dtype for return_res of 16, 32 and 64, that a dtype that is too small is rejected, and a record mixing format 61 with other formats. All of them fail on main.
  • uv run pytest -m "not network" -W error (571 passed), the network tests in tests/test_record.py (14 passed), ruff format --check and ruff check pass. Changelog entry added in changelog.d/.

Refs #484, #500

@tompollard 🟥 red 🐳 whale · quince

convert_dtype compared dtypes by parsing their names, which fails for
the big-endian dtype of format 61 (>i2). Use np.can_cast instead, which
also handles byte order.

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

Reviewed commit 8170c9a. I found no issues. The dtype check handles big-endian format 61 samples, returns the requested native dtype, and still rejects output dtypes that are too small. All 115 offline record tests pass. Docs and style checks pass; the test matrix is still running. Ready to merge once CI passes.

@tompollard
tompollard merged commit f59c445 into main Nov 24, 2026
18 checks passed
@tompollard
tompollard deleted the expanded-dtype-byte-order branch November 24, 2026 02:03
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.

1 participant