Skip to content

Add signal_names alias to Record and MultiRecord - #802

Merged
tompollard merged 2 commits into
mainfrom
api/record-attribute-names
Nov 30, 2026
Merged

tompollard merged 2 commits into
mainfrom
api/record-attribute-names

Conversation

@tompollard

@tompollard tompollard commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Add signal_names to Record and MultiRecord as a mutable alias for sig_name. The property reads and writes the existing list, so there is only one value to edit or serialize. The existing name continues to work without warnings.

Both constructors accept signal_names as a keyword-only argument and reject conflicting sig_name and signal_names values. The documentation explains that MultiRecord.signal_names remains None when its existing sig_name is unset, with source channel names available from source_signal_header after a read.

This is one attribute-naming step from #672. The count consistency question raised in review is tracked in #744.

Validation

  • Full offline suite: 1,343 passed, 4 skipped, 22 deselected
  • Ruff check and format check: 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. signal_names works well as an alias: one shared list, not stored separately, unaffected by copying and pickling, and renames reach the written header. Rejecting both spellings in the constructor is good too. The offline suite, Ruff and the strict docs build pass locally.

My concern is n_signals. As a writable alias of n_sig, it carries over a count that can disagree with the record:

  • On sample-data/100 (2 channels), record.n_signals = 5 makes both record.n_signals and record.metadata.n_signals report 5, but write recomputes the count from the data and the header says 2. The edit shows up in the API but never in the file.
  • After record.p_signal = record.p_signal[:, :1], both still report 2, and write fails with ValueError: non-broadcastable output operand with shape (4,1) doesn't match the broadcast shape (4,2).

The docs now describe this ("changing the list or a signal array does not update it"), which would fix it in place under the new name. Since n_signals is new, could it be read-only and derived from the current state instead: the number of columns or channels in the loaded signal array, otherwise len(signal_names), otherwise the header count? Alternatively, leave it out for now and rely on len(record.signal_names) and record.metadata.n_signals. n_sig would keep its current behaviour either way. Relatedly, metadata.n_signals currently follows an edited n_sig rather than the data. A derived count would fix that too, though it could be a separate change.

Optional: after read_record(..., combine_segments=False) on a multi-segment record, signal_names is None while n_signals is 7, because MultiRecord.sig_name isn't filled in. That's existing behaviour, but populating it from the layout or first segment would make the new name more useful, here or in a follow-up.

@tompollard tompollard changed the title Add readable aliases for record signal names and count Add signal_names alias to Record and MultiRecord Nov 30, 2026
@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I reproduced both n_sig mismatches. I removed the proposed n_signals property and constructor argument in ba42389. Deriving a count needs a decision about which signal array is authoritative when a Record holds more than one form, along with consistent behavior in Record.metadata and writing. I added the reproductions to #744, which already tracks the count and cross-field validation design.

This PR now adds only signal_names. It remains a direct alias of the existing sig_name list. For MultiRecord, I documented that the alias is None when sig_name is unset; after a signal read, source_signal_header gives the channel-defining names. The broader multi-segment metadata contract is tracked in #746.

The revised branch passes 1,343 offline tests, 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, dropping n_signals and recording the reproductions on #744 makes sense, since the count needs a decision about which signal array is authoritative. The PR is now just the signal_names alias, which works as before: one shared list, both constructor spellings rejected together, and renames reach the written header. Records have no n_signals attribute and Record(n_signals=...) raises the usual TypeError. The note that a MultiRecord's signal_names can be None, with source_signal_header (from #801) as the way to get channel names, is accurate: for 041s read with combine_segments=False it gives III, I, V, …. The offline suite, Ruff and the strict docs build pass locally.

Ready to merge once CI is green.

@tompollard
tompollard merged commit 4f8794b into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the api/record-attribute-names branch November 30, 2026 19:11
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