Skip to content

Add samples_per_frame alias to Record - #809

Merged
tompollard merged 2 commits into
mainfrom
feature/record-samples-per-frame
Nov 30, 2026
Merged

tompollard merged 2 commits into
mainfrom
feature/record-samples-per-frame

Conversation

@tompollard

@tompollard tompollard commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Add Record.samples_per_frame as a mutable alias for the existing per-channel samps_per_frame list. The Record constructor accepts either spelling and rejects both together. The new spelling accepts None or a list of positive integers, while direct assignment to the established field keeps its behavior. Both names refer to one stored list, including after reads, copies, and pickling.

The docs explain that expanded channel i contains n_frames * samples_per_frame[i] values. The alias works with channel selection and writing; the tests include an invalid edited multiplier that the writer rejects and a valid round trip. MultiRecord has no top-level per-channel list, so this PR leaves its signal metadata design to #441.

On a uniform read, the list can still describe the source file's frame layout even though the loaded array has one value per channel per frame. A uniform write stores one sample per frame for each channel. Expanded writes now validate every multiplier at write time, including after in-place list edits.

Related to #672 and #744.

Verification

  • Full offline suite: 1,431 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. samples_per_frame matches the name already used by SignalHeader and ExpandedSignals, shares one list with samps_per_frame through copies and pickling, and validates assignments the same way as n_signals and n_frames. I also checked every single-segment sample record (168 header-only and sample reads): all produce plain lists of integers, and assigning each back through the new name works, so the stricter setter won't reject values the readers produce. A wrong multiplier on an expanded write is rejected, and the corrected one round-trips. The offline suite, Ruff and the strict docs build pass locally.

Two optional notes:

  • On a uniform read of test01_00s_frame, samples_per_frame is [1, 2, 1] while p_signal has one value per frame, and a uniform write stores [1, 1, 1]. The docs explain the expanded case only. A sentence saying that on a uniform record it describes the source file, and that uniform writes store one sample per frame, would avoid confusion.
  • In-place edits bypass the setter (record.samples_per_frame[1] = 0 is accepted). On an expanded write this surfaces as ... expected 0 for samps_per_frame=0, which is correct but indirect. A write-time check that the values are positive would give a clearer message.

Ready to merge.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I addressed both notes in 9169e49. The docs now explain that a uniform read can retain the source frame layout in samples_per_frame while its loaded array has one value per channel per frame; a uniform write stores one sample per frame and leaves the source record unchanged. I added a regression test for that case.

Expanded writes now check that each multiplier is positive before calculating expected channel lengths, including after an in-place list edit and when n_frames is unset. The error names the channel directly. I added a test for that path and updated the PR description. The full offline suite passes (1,431 passed), as do Ruff and the strict docs build.

@tompollard
tompollard merged commit aadb7a7 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the feature/record-samples-per-frame branch November 30, 2026 20:50
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