Repository navigation
Require explicit alignment for skewed modern writes - #851
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The contract works as described. Apart from one docs gap below, this is ready to merge.
What I checked
- I wrote every record in
sample-datathroughwrite_recordandSignalRead.writeon this branch and onmain: digital, uniform and expanded, aligned andignore_skew=True(640 writes). For unskewed records the PR passed no option. For the 32 skewed writes (100skewand03700181), it passed the option matching the read:"aligned"for aligned reads,"raw"forignore_skew=True. Every successful write is byte-identical tomain, so choosing the option that matches the read reproduces the 5.14.0 output. - The writes that fail on
mainfail in the same way here. One variation isn't from this PR:n8_evoked_raw_95_F1_R9is rejected because of an invalid ADC field, and whether the error namesadc_zerooradc_resdepends onPYTHONHASHSEED, onmaintoo. The field checks presumably iterate over a set. That would be worth a small separate fix so the error is reproducible. - The library doesn't call
write_record,Record.writeorSignalRead.writeinternally, so no conversion or download path picks up the new requirement. SignalRead.writedeclares the alignment onto_legacy_record(), which is a deep copy, so the declaration can't outlive the write or change the read result.- The offline suite (1,715 passed, 4 skipped), Ruff, the strict docs build and CI all pass, and the towncrier draft renders the entry correctly.
One docs gap to fix
docs/migration.rst maps wrsamp and Record.wrsamp to write_record and Record.write, but doesn't mention the new requirement. Someone migrating a skewed record from wrsamp, which still infers alignment, will hit the new error with nothing in the guide about it. A sentence in that row, or in the write_record differences list further down, would help. For example: "For records with nonzero skew, pass signal_alignment="aligned" or "raw"."
Optional
SignalRead.write's docstring body still says "already applied skew is not applied again" without mentioning that the choice is now required. Only the parameter description says so.- The error could name the skewed channels (for example, "channel 1 (V5) has skew 3"). This would help when a record has many channels and the skew wasn't expected.
|
I added the missing migration note: skewed records written through The error now names each skewed channel and its value (for example, |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, 65ecc82 covers everything. The migration row now explains that the newer writers need signal_alignment for skewed records while wrsamp still infers it, and SignalRead.write's docstring says the same.
The new error names the skewed channels: "channel 1 (V5) has skew 3" for 100skew, "channel 2 (RESP) has skew 4" for 03700181, and plain "channel 1 has skew 3" when sig_name isn't a list. A test asserts this. Thanks also for filing #855.
The offline suite (1,715 passed, 4 skipped), Ruff and the strict docs build pass locally. CI is green, so this is ready to merge.
## Summary Use `signal_alignment="aligned" | "raw"` on `read_record` and `read_signals` in place of `ignore_skew`. The default remains aligned; `"raw"` retains the stored skew, equivalent to the old `ignore_skew=True`. Legacy `rdrecord` keeps its existing parameter. This deliberately changes the recently released modern reader signatures so reads and writes use the same words. The migration guide, API docs, and changelog explain the change. The migration guide also notes that newer signatures are still being refined before the next major release. Tests compare aligned and raw results with the legacy reader, reject invalid values and the removed modern keyword, and update the skew write tests to use the new read option. Part of #852. Rebases on `main` after #851 and #853. ## Verification - Offline suite: 1,715 passed, 4 skipped (`bxb` unavailable), 23 network tests deselected - Ruff check and format check: passed - Sphinx HTML build with warnings as errors: passed
Summary
Require
signal_alignment="aligned"or"raw"forwrite_record,Record.write, andSignalRead.writewhen a selected channel has nonzero skew. The error explains the two choices and is raised before files are created. Records without skew need no choice, and legacywrsampis unchanged.This deliberately changes behavior shipped in 5.14.0.
SignalReadis a frozen wrapper, but its NumPy arrays can be changed in place, so its writer cannot safely infer alignment from the original read. The option applies to one write and does not shift samples.The docs and changelog describe the contract. Tests cover aligned and raw reads, selected channels, uniform and expanded layouts, physical and digital values, in-place replacement, hand-built records, and copy/deepcopy/pickle.
Closes #843.
Verification
bxbunavailable), 23 network tests deselected