Repository navigation
Use a channel snapshot throughout header writes - #845
Conversation
tompollard
left a comment
There was a problem hiding this comment.
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 raisesValueError: units must have 2 channel entriesinstead ofTypeError: Field `units` must be a list., while tuples and NumPy arrays still get theTypeError. Checking the type before capturing the snapshot would keep strings consistent with those and withmain. - The clearer errors and the uniform
wrheaderfix are user-visible, so they could have a short changelog entry.
Otherwise ready to merge.
|
Thanks for checking the header output against the merge base. I addressed both points in a8a9551. The writer now raises the existing 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
left a comment
There was a problem hiding this comment.
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.
|
Agreed. I changed the pre-snapshot check in f291f51 to require a list for every non- The 50 focused tests and Ruff pass. CI is running on the updated commit. |
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
Recordlists remain themutable 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