Repository navigation
Reject writes with ambiguous skew provenance - #844
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. Rejecting a changed skew after an ignore_skew=True read is a clear improvement, and pickling, copy.copy and deepcopy behave correctly with the new state. The offline suite, Ruff and the strict docs build pass locally.
I'm not sure about the replacement rule, though. Any new array counts as replaced, including ones derived from the aligned values, so common processing on a skewed record now fails with "Cannot write skew after replacing loaded signal values". On 100skew, each of these writes correctly on main and raises here:
r.p_signal = r.p_signal - r.p_signal.mean(axis=0), thenwrite_recordr.d_signal = r.d_signal[50:150](withsig_len = 100), thenwrite_recordrdrecord,p_signal = medfilt(p_signal, [3, 1]), thenwrsamp
Values derived from aligned values are still aligned, and the case from #843 (assigning raw unaligned values to an aligned record) seems much rarer than filtering or trimming. Could we keep main's behaviour for replaced arrays (treat them as aligned and document that), keep the ignore_skew=True check, and drop the weak references and the __getstate__, __setstate__ and __deepcopy__ overrides that exist only for the replacement rule?
Separately, _skew_for_write gains a branch for a skew list longer than n_sig whose first n_sig entries are empty, which returns None before the other checks. What case is that for? It isn't covered by a test or mentioned in the description.
|
Thanks, I agree. Array identity cannot tell whether replacement values came from filtering aligned data or from an unaligned read, and rejecting every replacement would break useful workflows. I updated the PR to keep writes of processed arrays working. Tests now cover normalizing an aligned physical array with The extra I changed the PR from |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, this version is much simpler. Mean subtraction, trimming and medfilt followed by wrsamp on 100skew all write as on main again, and changing skew after an ignore_skew=True read is now rejected clearly through both write_record and wrsamp (on main it either raised a broadcasting error or wrote a bad file). channels=[1] reads and clearing skew are unaffected. The offline suite, Ruff and the strict docs build pass locally.
One case from #842 comes back in a new form: after an ignore_skew=True read, keeping only channel 1 by hand (slicing d_signal and every per-channel list, n_sig = 1) leaves skew == [3], which is that channel's original skew. main writes it correctly ([3], reads back as (200, 1)), but here it raises "Cannot write new skew after an ignore_skew=True read" because [3] is compared with (None, 3) as a whole. When the lengths differ, could the check accept a skew list that appears in _read_skew in order, or otherwise raise the channel-count error pointing to read_record(..., channels=[...]), as in #842?
|
Thanks, you’re right: comparing the whole list rejected a valid manual channel subset. I changed the check in b5befc4 so a shorter skew list is accepted when its values remain an ordered subset of the skew from the I added tests for the accepted and rejected manual subsets through both One separate limit remains on #843: a short |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, b5befc4 handles it. After an ignore_skew=True read, keeping channel 1 by hand now writes skew [3], keeping channel 0 writes no skew, a mismatched [4] gets the read_record(..., channels=[...]) guidance, and a same-length change still gets the "new skew" error. Thanks also for recording the short-read tail-sample case on #843. The offline suite, Ruff and the strict docs build pass locally.
Ready to merge once CI is green.
Summary
Reject assigning a different nonzero skew after an
ignore_skew=Trueread.The loaded values may not contain the extra samples required by that new
skew, so both writers now fail before creating files. The skew declared by
the source remains writable.
Manual channel subsets can retain skew values in their original source order;
an unmatched subset gets guidance to use
read_record(..., channels=[...]).Signal arrays derived from an aligned read, such as filtered or trimmed
values, remain writable. Writers assume replacement arrays retain the loaded
values' alignment. Raw unaligned values should instead be written from an
ignore_skew=Trueread. This contract is documented on both write APIs.The check uses a small tuple of the source skew. It survives ordinary record
copying and pickling without custom serialization or weak references.
Refs #843. The broader question of how callers can explicitly mark the
alignment of arbitrary replacement arrays remains open there.
Validation
The offline suite, Ruff, and the strict Sphinx build pass. Tests cover both
writers, selected channels, filtered and trimmed aligned values, and copied
or pickled records. The full offline suite passes with 1,639 tests.