Repository navigation
Share digital write feature calculation - #890
Conversation
tompollard
left a comment
There was a problem hiding this comment.
This shares the feature calculation correctly, and it can merge. The fixture, parity and feature tests pass (413 passed, 44 expected skips), as do the offline suite (2,279 passed, 48 skipped) and Ruff.
What I checked
_digital_feature_values returns exactly what the removed lines assigned, in the same order: sig_len from samps_per_frame[0] for expanded values, n_sig, initial values and checksums. As with #889, I compared the public Record.set_d_features() with main (a988bfe) on 3,000 random records. They had 1 to 3 channels and 0 to 4 frames, uniform or expanded, do_adc on or off, and fmt, calibration and samps_per_frame each sometimes missing. After each call I compared the resulting attributes, or the error.
- All 2,071 successful calls give identical attributes, and every error type and message is unchanged.
- 423 calls differ in one way, and it's an improvement. With zero-frame arrays, both versions raise
IndexError: index 0 is out of bounds for axis 0 with size 0from the initial-value calculation. Onmain,sig_len=0andn_sighad already been assigned when it failed, so the record was left half-updated. Here, the tuple assignment means nothing changes unless every value was calculated.
Minor
The description says there's no public behaviour change. Strictly, the partial update on failure is gone. I don't think it needs a changelog entry, since it only affects calls that already raise. But a one-line test that a failing set_d_features() leaves sig_len and n_sig unchanged would pin the new behaviour, rather than leaving it as a side effect of the refactor.
|
Thanks for checking the public setter against main, especially its error I added uniform and expanded regression cases in 9eecb3e, updated the PR |
## Summary Continue #866 after #890 by moving flattened multi-segment write preparation out of `Record._prepare_flattened_write`. - A private helper takes the selected units, formats, file names, calibration, and arrays explicitly. It preserves the format-32 fallback and translates missing-sample markers when digital channels need a common format. - The public legacy `Record.wrsamp` path retains its private wrapper. The modern `_WriteModel` calls the shared helper directly and no longer borrows `Record._prepare_flattened_write`. - Add tests for mixed-format marker recoding without changing input arrays, physical fallback calibration, and the model's independence from the Record method. The helper is shared by both write paths, so the differential test alone cannot catch a mistake inside it. I also compared this branch with the pre-change main checkout (`87ba3c3`) across 24 flattened write cases from five sample masters, both kinds and layouts, plus a full-length `041s` read. All 12 successful cases produced the same file names and bytes; the other 12 failed with the same exception type and message. The fixed 5.17.0 flattened fixture also passes. No public behavior change is intended. ## Checks - Full offline suite: 2,284 passed, 48 skipped, 23 deselected - Writer byte fixtures and parity comparisons passed - Ruff check and format passed - Sphinx docs build passed with warnings as errors
Summary
Continue the #866 cleanup after #889 by sharing the digital feature
calculation used by the modern write model and the public
Record.set_d_features()method.samps_per_frame. It returns frame and channel counts, initial values,and checksums.
Recordkeepsits public signature, conversion logic, and mutation behavior; the model
still prepares calibration separately.
The 5.17.0 byte fixtures and differential parity tests remain in place.
Successful calls and release bytes are unchanged. On an empty digital array,
Record.set_d_features()still raisesIndexError, but now leavessig_lenand
n_sigunchanged rather than partially updating them. A regression testand changelog entry cover that failure-state improvement.
Checks
deselected; 41 focused feature and byte-fixture tests pass after the new test