Skip to content

Keep source headers separate during single-segment reads - #754

Merged
tompollard merged 2 commits into
mainfrom
separate-single-read-source
Nov 28, 2026
Merged

tompollard merged 2 commits into
mainfrom
separate-single-read-source

Conversation

@tompollard

@tompollard tompollard commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Carry the parsed source header through single-segment reads. A header-only
Record is materialized once for validation and reading, then that same object
becomes the selected public result. A private read result keeps the parsed
source fields, selected samples, channel selection, and read options together
while the result is built.

Header-only reads, multi-segment reads, .wfdb archives, and DataFrame chunks
use the same parsed-header loader and materialize independent Record or
MultiRecord objects. The iterator cache now holds parsed fields, so editing a
returned record cannot alter source metadata for later windows.

This is the first internal step for #743. It makes no public API or output
change and adds no second mutable metadata object to Record.

Verification

  • Added an integration test that reads two windows with a shared header cache,
    edits the first returned record, and verifies the second result and cached
    parsed fields remain unchanged.
  • Offline suite: 903 passed, 4 skipped, 21 deselected (MPLBACKEND=Agg).
  • Sphinx HTML build with warnings as errors passed.
  • Ruff check and format check passed.

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

I found one design and test concern, not a reproduced output regression.

_rdrecord materializes a mutable Record from source_header before validation and signal reading (src/wfdb/io/record.py:2725-2728), then _record_from_single_segment_read materializes a second Record from that same header after the read (:2821-2832). Any derived field changed on the first object must be copied into the parsed header for the returned object; sig_len already needs this explicit synchronization (:2732-2739). That leaves two states to keep aligned as the read path evolves. Please consider keeping one materialized read record while retaining the parsed source separately, or make the transfer of derived fields explicit in one place.

The new test_selected_records_do_not_change_the_source_header calls _record_from_single_segment_read with synthetic values. It does not exercise the _rdrecord handoff or its cache. Add an integration test that makes two _rdrecord calls with the same header_cache, edits the first returned record, and checks the second record and cached parsed fields. I ran that scenario manually and it currently passes; the request is to guard the path this PR changes.

The affected offline tests passed (276 passed, 14 deselected). I did not find a current user-visible regression.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for the careful review. Addressed both points in de28bc2.

_rdrecord now materializes one Record for validation and reading, then
uses that same object for the selected result. The parsed source header stays
separate; the output no longer depends on constructing a second Record and
transferring derived fields to it.

I replaced the synthetic test with an integration test that calls _rdrecord
twice using the same header_cache, edits the first returned record, and checks
the second result and cached parsed fields. The offline suite passes (903
passed, 4 skipped); Ruff checks pass. I also updated the PR description to
match the revised flow.

@tompollard
tompollard merged commit a81e122 into main Nov 28, 2026
19 checks passed
@tompollard
tompollard deleted the separate-single-read-source branch November 28, 2026 01:40
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