Repository navigation
Add n_signals alias for declared record channel count - #805
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. The alias itself works: one stored value, both constructor spellings rejected together, and it survives copying and pickling. Since #803 and #804, an edited count on a single-segment Record is caught at write time. The offline suite, Ruff and the strict docs build pass locally.
Two things I'd fix first:
MultiRecordwrites aren't checked. The docs say "the writers reject inconsistencies", but on041sread withcombine_segments=False, settingn_signals = 9(7 signals) and callingwrsampwrites041s/1 9 125 10 .... Reading that back fails withValueError: Input channels must all be lower than the total number of channels, andwfdb checkreports "No WFDB problems found". CouldMultiRecord.wrsampcheck the declared count against its segments, or the docs limit the claim to single-segment writers? Thewfdb checkgap probably deserves its own issue.- The new name accepts any value.
record.n_signals = "3",-1,Trueand2.5are all stored, andRecord(n_signals="2")works. Since this is a new name, could the setter and constructor argument raiseTypeErrorfor non-integers (includingbool) andValueErrorfor negatives, leavingn_sigitself unchanged?
On the design: this settles #744's question of which count is authoritative as a declared count checked at write time, which makes sense for header-only and multi-segment records. It would be good to record that decision on #744, since a mismatch is still visible in memory before writing. After slicing p_signal to one column, n_signals, metadata.n_signals and len(metadata.signals) all still say 2. Minor wording: metadata.n_signals is recalculated from the declared count on each access rather than being a snapshot.
|
Thanks, these were good catches. I pushed d233d19 to address both blocking points:
I corrected the docs to say that each The full offline suite passes (1,387 passed), as do Ruff and the strict docs build. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, d233d19 covers both points. Setting n_signals = 9 on 041s (fixed) or p000878 (variable) now fails before writing, naming the real count (7 or 4), with no files left behind. I compared main and this branch on eight MultiRecord.wrsamp cases (full reads, channel subsets and reordering, variable-layout name selection with and without force_channels, and read_record(..., combine_segments=False)), and all behave the same and read back correctly, so the new check doesn't affect valid writes. The setter and constructor now reject strings, booleans (including np.True_), floats and negatives, while accepting np.int64 and None, and n_sig keeps its legacy behaviour. The decision note on #744 and #806 for the checker gap look good. The offline suite, Ruff and the strict docs build pass locally.
One small nit: the new MultiRecord messages say "n_sig must match ...", even when the count was set through n_signals. Mentioning both names would help, but it's fine as is.
Ready to merge once CI is green.
|
Thanks for checking the fixed- and variable-layout cases. I took the wording suggestion in 33276b2: both |
Summary
Add
n_signalsas a mutable alias for the existingn_sigfield onRecordandMultiRecord. Both constructors accept the new keyword and reject simultaneous values for both spellings. The alias adds no second stored count and does not change existing read or write behavior.n_signalsmeans the declared number of channels in the current record view. It is available on header-only records and is not inferred from whichever signal array happens to be loaded. Editing it does not resize arrays or per-channel fields; the writers now reject count mismatches before writing.Record.metadata.n_signalsremains a snapshot of the declared count.This is a small naming step for #672 and addresses the count-name question in #744. The broader per-channel metadata design remains open.
Verification