Repository navigation
Validate selected channels before legacy record writes - #804
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. I compared main and this branch on 15 Record.wrsamp cases: edited n_sig, short or long sig_name, units, skew, init_value, byte_offset, checksum, adc_res, block_size and samps_per_frame, a sliced p_signal, a hand-built record, and the module-level wfdb.wrsamp. Everything this PR rejects was already rejected on main, often as IndexError: list index out of range or the broadcasting error. The cases that wrote before (a stale checksum, the module-level function) still do. So this improves errors without breaking legacy behaviour. Checking only the form wrsamp will write, and ignoring only checksum here while byte_offset and init_value are kept, both look right. The offline suite, Ruff and the strict docs build pass locally.
Two optional notes:
- With
n_sigunset,wrsampstill fails withTypeError: '>' not supported between instances of 'NoneType' and 'int'(and a hand-builtRecord(p_signal=..., sig_name=..., ...)fails with a NumPyUFuncTypeError), as onmain.write_recordinfersn_sigfrom the array, and doing the same here, or raising a clear message, would cover the last confusing case. It only affects calls that fail today, so a follow-up is fine. - Since some failures change from
IndexErrortoValueError, a short note in the changelog might help anyone catching the old type.
Ready to merge once CI is green.
|
Thanks for checking the legacy cases. I addressed both notes in 59080b6. I added a regression test for a hand-built record without |
Summary
Validate the signal form selected by
Record.wrsamp()againstn_sigand retained per-channel header fields before ADC conversion or file creation. This replaces the NumPy broadcasting error after slicing a physical signal array with an actionableValueErrorthat names the mismatched fields.The legacy writer continues to prefer digital values when both forms are loaded. It still recalculates
checksum; unlikewrite_record(), it retainsbyte_offsetandinit_value, so those fields are checked. This addresses the legacy writer example noted in #744 without closing that broader issue.Verification