Skip to content

Use a channel snapshot throughout header writes - #845

Merged
tompollard merged 3 commits into
mainfrom
refactor/header-write-snapshot
Dec 2, 2026
Merged

tompollard merged 3 commits into
mainfrom
refactor/header-write-snapshot

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

The single-segment header writer now captures the current per-channel fields
once and uses that snapshot to choose fields, validate their values and file
grouping, and render signal lines. The existing Record lists remain the
mutable source; in-place edits are reflected in the next write. A uniform
header still ignores samples_per_frame.

Tests cover in-place edits, conflicting formats or byte offsets for a shared
signal file, and the uniform-header case. This is an internal step toward
#749 and #744; it does not add or rename a public API.

Validation

  • Offline suite: 1,631 passed, 4 skipped, 23 network tests deselected.
  • Ruff check and format pass.
  • Sphinx builds with warnings treated as errors.

@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: writing every header in sample-data with wrheader (expanded and uniform) and wrsamp (uniform and expanded) gives byte-identical files to the merge base across 352 writes, and the writes that fail there fail the same way here. The new snapshot also improves several errors: a short sig_name, skew or samps_per_frame, or a wrong n_sig, now gives "… must have N channel entries" instead of IndexError: list index out of range, and wrheader(expanded=False) with an unused samps_per_frame=[2] now writes instead of raising IndexError. The offline suite, Ruff and the strict docs build pass locally.

Two small optional points:

  • A string field such as units="mV" now raises ValueError: units must have 2 channel entries instead of TypeError: Field `units` must be a list., while tuples and NumPy arrays still get the TypeError. Checking the type before capturing the snapshot would keep strings consistent with those and with main.
  • The clearer errors and the uniform wrheader fix are user-visible, so they could have a short changelog entry.

Otherwise ready to merge.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the header output against the merge base. I addressed both points in a8a9551.

The writer now raises the existing TypeError when a per-channel field is a string or bytes, before capturing the snapshot. I added a regression test for units="mV". I also added a changelog entry for the clearer channel-count errors and the uniform wrheader behavior.

The 47 focused tests, Ruff, and the strict docs build pass. The full offline suite passed before this small follow-up (1,631 tests).

@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, a8a9551 restores the TypeError for string and bytes fields, and the changelog entry reads well. The full offline suite, Ruff and the strict docs build pass locally after this commit.

One small follow-on: a number in place of a list still changes type. adc_gain=200.0 or baseline=0 raised TypeError: Field `adc_gain` must be a list. on main and now raises ValueError: adc_gain must have 2 channel entries. Since the header writer only accepts lists for these fields anyway, checking value is not None and not isinstance(value, list) instead of (str, bytes) would cover both cases. Not blocking.

Ready to merge once CI is green.

@tompollard

Copy link
Copy Markdown
Member Author

Agreed. I changed the pre-snapshot check in f291f51 to require a list for every non-None per-channel field. That restores the TypeError for numeric scalars such as adc_gain=200.0 and baseline=0, as well as strings and tuples. I added regression cases for each of those forms.

The 50 focused tests and Ruff pass. CI is running on the updated commit.

@tompollard
tompollard merged commit 0b45f2b into main Dec 2, 2026
19 checks passed
@tompollard
tompollard deleted the refactor/header-write-snapshot branch December 2, 2026 04:56
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