Skip to content

Add formats alias to Record - #812

Merged
tompollard merged 2 commits into
mainfrom
feature/record-formats
Nov 30, 2026
Merged

tompollard merged 2 commits into
mainfrom
feature/record-formats

Conversation

@tompollard

@tompollard tompollard commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Add Record.formats as a mutable alias for the per-channel fmt list in #672. The constructor accepts either spelling and rejects both together. Reads, copies, pickling, and writes use the same stored list. MultiRecord keeps its segment-level format information and has no top-level formats field.

The alias describes WFDB file encoding. Assignments through formats accept None or a list of known WFDB format codes, including read-only codes such as 310 and 0 for null channels. Direct fmt assignment keeps its existing behavior. The writer continues to validate whether the selected formats can be written with the record's files and signal values.

Verification

  • Full offline suite: 1,449 passed, 4 skipped, 22 deselected.
  • Eleven focused format-alias tests passed.
  • 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. formats shares one list with fmt through copies and pickling, both constructor spellings are rejected together, channel selection keeps the right format, and an edited format reaches the written header. Leaving it off MultiRecord matches samples_per_frame. The offline suite, Ruff and the strict docs build pass locally.

One difference from the other new names: samples_per_frame, n_signals, n_frames, channels and the annotation aliases all validate assignments through the new spelling, but formats stores anything. "16", [16], ["999"], ("16", "16") and ["16", None] are all accepted, and only fail at write time, some with legacy-style messages: a tuple gives TypeError: Field 'fmt' must be a list., and ["16", None] gives TypeError: ('Channel 1 of field 'fmt' must be one of the following types:', ...). All 82 sample headers produce lists of strings, so validating on assignment wouldn't reject anything the readers produce. Could the setter and constructor keyword require None or a list of strings, each a known WFDB format code (including read-only ones such as 310, with writability still checked when saving), leaving fmt unchanged?

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I agree. formats now accepts None or a list of known WFDB format-code strings, including read-only codes such as 310 and 0 for null channels. It rejects the scalar, tuple, numeric, missing, and unknown-code cases you listed at assignment time. Direct fmt assignment keeps its existing behavior; the writer still checks whether a known format can be written with the record. I added tests for the accepted and rejected cases in commit 63f48d0. All 11 focused tests, Ruff, and the strict docs build pass.

@tompollard
tompollard merged commit 9b7337d into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the feature/record-formats branch November 30, 2026 22:21
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