Skip to content

Separate current storage fields from logical metadata - #841

Merged
tompollard merged 3 commits into
mainfrom
feature/current-signal-encoding
Dec 2, 2026
Merged

tompollard merged 3 commits into
mainfrom
feature/current-signal-encoding

Conversation

@tompollard

@tompollard tompollard commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

This continues #744 by separating logical channel metadata from the current Record's storage declarations within the on-demand channel snapshot.

  • _SignalFieldSnapshot.storage groups file name, format, samples per frame, skew, offsets, and other storage fields for each channel. Skew is the current declared field; loaded values may already have it applied.
  • Record.metadata.signals now projects its logical fields from the same snapshot builder. A malformed storage list does not hide otherwise valid logical metadata.
  • The dat writer consumes the grouped storage view. The public Record lists remain the only mutable owner of these values, and source_header remains the description of the original file.

The storage view stays internal in this PR. It describes fields currently declared on a Record; it is not an exact byte-level write plan, since writing may rename files, clear offsets, or omit already applied skew. This keeps the public naming and semantics open for review before adding an API.

Verification

New tests cover selected records with skew, manual records without a source, in-place edits, incomplete storage fields, and variable-layout headers. A review follow-up also rejects strings as per-channel lists in Record.metadata, with a regression test and changelog entry. The full offline suite, Ruff, and the strict Sphinx build pass.

Refs #744 and #749.

@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. Nothing user-visible changes: Record.metadata matches the merge base for every record in sample-data and for odd manual records (short lists, invalid skew, NumPy arrays, missing or boolean n_sig), and write_record writes byte-identical files for every single-segment sample record. The offline suite, Ruff and the strict docs build pass locally.

One thing I'd change:

  • skew_applied is decided for the whole record. _capture_signal_fields sets the flag only when the whole skew list still equals _applied_skew. On 100skew that gives [(None, False), (3, True)] after a read, but after changing only channel 0's skew to 1 it gives [(1, False), (3, False)], although channel 1's samples are still realigned by 3. Nothing reads skew_applied yet, so it's latent, but it would be safer to compare each channel with its own _applied_skew entry, or to leave the field out until a consumer needs it.

Optional, and already the case on main: now that Record.metadata is built with _capture_signal_fields, a string still passes the length check, so Record(n_sig=2, sig_name="II").metadata.signals has two channels named "I". The write path rejects strings as "not a per-channel sequence"; applying the same rule here would give None rather than wrong names.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks. I addressed both points in 6ce9417.

I removed skew_applied from the storage view. Nothing consumes it yet, and the writer currently decides whether to omit skew using the full list. A per-channel flag would imply semantics the writer does not yet follow. The view still reports the current declared skew field, and the PR description now makes that distinction clear.

I also made _capture_signal_fields reject strings and bytes as per-channel lists. Record(n_sig=2, sig_name="II").metadata.signals now returns None instead of two "I" channels. There is a regression test and a changelog entry.

The full offline suite passes (1,623 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, 6ce9417 covers both. Dropping skew_applied makes sense while the writer still decides from the whole list. String channel fields now give metadata.signals is None, including a one-channel sig_name="I", which matches the writers (wrsamp and write_record reject units="V" with the same message as before), and channel-selected reads are unchanged. The offline suite, Ruff and the strict docs build pass locally.

Tiny nit: the final assert hasattr(record, "metadata") in test_metadata_rejects_string_channel_field can't fail after the two lines above it.

Ready to merge once CI is green.

@tompollard

Copy link
Copy Markdown
Member Author

Agreed. I removed the redundant hasattr assertion in 9955773. The metadata tests still pass (21 passed), as do Ruff and formatting checks. I'll wait for CI on the updated commit before merging.

@tompollard
tompollard merged commit eae4afd into main Dec 2, 2026
19 checks passed
@tompollard
tompollard deleted the feature/current-signal-encoding branch December 2, 2026 02:39
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