Skip to content

Capture channel metadata once for record writes - #838

Merged
tompollard merged 2 commits into
mainfrom
feature/writer-record-spec
Dec 2, 2026
Merged

tompollard merged 2 commits into
mainfrom
feature/writer-record-spec

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

This starts the write-side work in #749. write_record() now validates and captures the selected record's per-channel fields once, then projects that captured view onto its private writable copy. The header and data writers use the same checked channel values for file names, formats, offsets, and samples per frame.

The snapshot is temporary and is never attached to Record. In-place edits to legacy field lists remain visible to the next write, while existing equality and serialization behavior remain unchanged. SignalRead.write() uses the same preparation path.

Expanded writes now treat an omitted per-channel samps_per_frame value as one throughout the write. Previously, validation accepted that default but conversion could fail before writing.

Scope

Refs #749. This PR covers the write boundary. The parser's projection into mutable Record fields, annotation internals, and structural equality questions in #749 remain separate work.

Verification

  • Offline suite: 1,607 passed, 4 skipped, 23 deselected.
  • Ruff check and format checks pass.
  • Strict Sphinx docs build passes.

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

Thanks. Output is unchanged: write_record and SignalRead.write produce byte-identical .hea and .dat files to main for uniform and expanded, digital and physical writes of drive02-no-len (multiple samples per frame). A record read with skew writes the same header as before, and MultiRecord.wrsamp and header-only records behave as on main. The samps_per_frame=[None, 2] expanded write now works. The offline suite, Ruff and the strict docs build pass locally.

Two things I'd change:

  • Two snapshot builders. _header._capture_signal_write_snapshot and the end of record._snapshot_record_write_channels build the same _ParsedSignalLine tuple; only the rule for which fields count as present differs. Could the record helper pass its present_fields to the _header one, so there's a single place that builds the per-channel view?
  • Test. assert "_write_snapshot" not in vars(source) can't fail, since nothing sets that attribute. The middle of the same test drives the private helpers with an edit between capture and preparation, which no public writer can do; the public source.write(path) part seems enough.

A side effect worth noting: write_record now accepts per-channel fields given as a NumPy array or tuple (adc_gain=np.array(...) fails on main with "Field adc_gain must be a list"), because the private copy is projected to lists. That's an improvement, but it could go in the changelog with a test so it doesn't regress unnoticed.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I addressed all three points in 4498018.

  • Both write paths now use _capture_signal_write_snapshot to build the per-channel view.
  • I replaced the private-helper test with two public writes after in-place edits, checking that each output reflects the current channel names.
  • I added a round-trip test for NumPy array and tuple channel fields and documented that accepted input in the changelog.

The full offline suite passes (1,608 passed, 4 skipped), as do Ruff and the strict docs build.

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

Thanks, 4498018 covers all three: both write paths now build the per-channel view with _capture_signal_write_snapshot, the test checks two public writes after in-place edits, and NumPy array and tuple fields have a round-trip test and a changelog line. A NumPy gain with an int32 baseline writes a normal header, and SignalRead.write still works. The offline suite, Ruff and the strict docs build pass locally.

Ready to merge once CI is green.

@tompollard
tompollard merged commit 7435eab into main Dec 2, 2026
19 checks passed
@tompollard
tompollard deleted the feature/writer-record-spec branch December 2, 2026 00:28
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