Repository navigation
Add signal_names alias to Record and MultiRecord - #802
Conversation
tompollard
left a comment
There was a problem hiding this comment.
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 = 5makes bothrecord.n_signalsandrecord.metadata.n_signalsreport 5, butwriterecomputes the count from the data and the header says2. The edit shows up in the API but never in the file. - After
record.p_signal = record.p_signal[:, :1], both still report 2, andwritefails withValueError: 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.
|
Thanks, I reproduced both This PR now adds only The revised branch passes 1,343 offline tests, Ruff, and the strict docs build. |
tompollard
left a comment
There was a problem hiding this comment.
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.
Summary
Add
signal_namestoRecordandMultiRecordas a mutable alias forsig_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_namesas a keyword-only argument and reject conflictingsig_nameandsignal_namesvalues. The documentation explains thatMultiRecord.signal_namesremainsNonewhen its existingsig_nameis unset, with source channel names available fromsource_signal_headerafter a read.This is one attribute-naming step from #672. The count consistency question raised in review is tracked in #744.
Validation