Repository navigation
Validate record channel counts before writing - #803
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks, this fixes both cases from #744. An edited n_sig now fails clearly before any file is written (for all four forms), a sliced p_signal gets a readable error instead of the broadcasting failure, only the selected form is checked, and an unset n_sig is still filled on the copy. The offline suite, Ruff and the strict docs build pass locally.
Two things I'd change before merging, both about writing a subset of channels from a loaded record:
- Fields the writer replaces are still checked. The check covers all 14 per-channel fields, but the writer recalculates
checksumandinit_value(edited values came back as3980, 4044and995, 1011) and clearsbyte_offset. So a record can be rejected over values that never reach the file. Could those three be skipped, or the check run on the prepared copy? - One mismatch is reported at a time. On
sample-data/100, after slicingp_signalto one column and trimmingn_sig,sig_name,units,fmt,adc_gain,baselineandfile_name,writestill failed eight more times, once each forsamps_per_frame,skew,byte_offset,adc_res,adc_zero,init_value,checksumandblock_size. Listing every mismatched field in one message would help, and so would pointing toread_record(..., channels=[...])for subsets.
Optional: a non-integer n_sig (e.g. "2") raises ValueError, while the new readers use TypeError for wrong types. Also, the legacy Record.wrsamp still hits the broadcasting error on a sliced array. That's fine to leave here, but it may be worth noting on #744.
|
Thanks, fixed in 30e4305. The early check now skips The error now lists every retained field with the wrong channel count in one message and points to I reproduced the legacy |
Summary
Validate the selected signal array, a stated
n_sig, and retained per-channel header fields beforewrite_recordorRecord.writeprepares the output. A mismatch now raises aValueErrorlisting every field with the wrong count before files are created, with guidance to useread_record(..., channels=[...])for subsets.byte_offset,init_value, andchecksumare excluded because the writer clears or regenerates them; unchanged source skew already applied to the values is excluded too.This addresses the two concrete failures discussed in #744: a manually edited
n_sigwas silently replaced by the array width, and slicing an array without updating the count produced a NumPy broadcasting error during writing. The validation applies to the selected physical or digital, uniform or expanded form. Whenn_sigis unset, the writer fills it from that form on its copy of the record; the caller's object remains unchanged.This is a focused part of #744. The broader decision about a derived public
n_signalsvalue andRecord.metadataremains there.Validation