Skip to content

Add n_frames alias for record frame count - #808

Merged
tompollard merged 1 commit into
mainfrom
feature/record-n-frames
Nov 30, 2026
Merged

tompollard merged 1 commit into
mainfrom
feature/record-n-frames

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Add n_frames as a mutable alias for sig_len on Record and MultiRecord, including a keyword-only constructor argument. The two names share one stored value. Assignment through the new name accepts non-negative integers or None, following the n_signals pattern.

sig_len counts base sample frames. An expanded channel can have more samples than frames, so n_frames describes this value more precisely than the provisional signal_length name in #672. The name also matches read_header and Record.metadata.

While testing this alias, I found that write_record silently recalculated an edited sig_len from the array. It now checks a declared frame count against the selected uniform or expanded values before writing. When the count is unset, it still derives it on a copy of the record. Tests cover both record classes, expanded values, selections, serialization, invalid inputs, and writer behavior.

Related to #672 and #744.

Verification

  • Full offline suite: 1,416 passed, 4 skipped, 22 deselected.
  • Ruff format and lint passed.
  • Strict Sphinx HTML build 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.

Thanks. n_frames fits well: one stored value with sig_len, the same validation as n_signals (strings, floats, booleans and negatives rejected; np.int64 stored as int), and the name matches read_header and metadata and counts frames rather than expanded samples. To check the new write-time frame check for false positives, I wrote every single-segment sample record in all four forms with full, partial and ignore_skew reads (984 combinations), and main and this branch gave identical results. Real mismatches are caught: trimming p_signal to 3 rows gives sig_len (n_frames) is 4, but p_signal has 3 frames, updating n_frames to 3 writes a valid header, and shortened expanded channels are caught per channel. The offline suite, Ruff and the strict docs build pass locally.

Not for this PR: the legacy wrsamp prints sig_len, n_sig and the array shape to stdout before raising sig_len and n_sig do not match shape of d_signal. Folding those values into the message would be a small follow-up.

Ready to merge once CI is green.

@tompollard
tompollard merged commit 4ed60d1 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the feature/record-n-frames branch November 30, 2026 20:38
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