You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Define skew provenance when signal values or skew are edited before writing #843
The writer uses _applied_skew to decide whether signal values have already been aligned. That marker can become stale when a caller replaces the signal array, and a newly assigned skew on an unaligned read can request samples that the written dat file does not contain.
Two pre-existing cases need a defined write contract:
Read sample-data/100skew normally, replace its digital signal values with values from an ignore_skew=True read, and write it. _applied_skew remains set, so the writer omits skew and silently changes the alignment of the output.
Read sample-data/100skew with ignore_skew=True, assign a new nonzero skew, and write it. Writing succeeds, but reading the output can raise ValueError: could not broadcast input array ... because the dat file lacks samples for the new skew.
Expected behavior
Writing should either preserve the intended alignment with enough encoded samples or reject an unsupported edit before creating files. The behavior should be tested for both Record.write() and Record.wrsamp(), including selected records. We should avoid relying on a provenance marker that can disagree with the current signal arrays.
Related: #744 and #842. #842 handles newly assigned skew on values that were already aligned, but does not settle these two cases.
Update after the review of #844: the PR now fixes the changed-skew case for an ignore_skew=True read. It no longer rejects every replacement array, because filtering or trimming aligned values commonly creates a new array. The documented write contract assumes replacements retain the loaded values' alignment. That leaves the first example here open: the library cannot infer whether an arbitrary assigned array is aligned or raw, so an explicit way to declare or change that alignment may be needed.
I also reproduced a related selected-read case. Reading sample-data/100skew with ignore_skew=True, sampto=100, physical=False, and smooth_frames=False, then writing it with its unchanged skew, produces an output whose aligned read has missing values in the last three frames of the skewed channel. The original aligned read has values there. The selected raw array contains only 100 samples, while the source has additional samples needed to apply skew at the selection's end. We should either preserve those extra samples when writing or reject this write before creating files. This is separate from changing the skew value.
I opened #851 to require an explicit signal_alignment choice for all three modern writers when a channel has nonzero skew. SignalRead needs the same rule as Record: its wrapper is frozen, but its NumPy values can still be overwritten in place, so the original read cannot tell the writer how the current values are aligned.
I considered making SignalRead arrays read-only so its writer could infer alignment. That would break in-place arithmetic, and NumPy's writable flag can be turned back on, so it would not provide a reliable guarantee. The explicit choice is simpler and consistent across the three writers.
Activity
tompollard commentedon Dec 2, 2026
Update after the review of #844: the PR now fixes the changed-skew case for an
ignore_skew=Trueread. It no longer rejects every replacement array, because filtering or trimming aligned values commonly creates a new array. The documented write contract assumes replacements retain the loaded values' alignment. That leaves the first example here open: the library cannot infer whether an arbitrary assigned array is aligned or raw, so an explicit way to declare or change that alignment may be needed.I also reproduced a related selected-read case. Reading
sample-data/100skewwithignore_skew=True,sampto=100,physical=False, andsmooth_frames=False, then writing it with its unchanged skew, produces an output whose aligned read has missing values in the last three frames of the skewed channel. The original aligned read has values there. The selected raw array contains only 100 samples, while the source has additional samples needed to apply skew at the selection's end. We should either preserve those extra samples when writing or reject this write before creating files. This is separate from changing the skew value.Reject writes with ambiguous skew provenance (#844)
Reject shortened raw skew reads before writing (#846)
Declare replacement signal alignment per write (#849)
tompollard commentedon Dec 2, 2026
I opened #851 to require an explicit
signal_alignmentchoice for all three modern writers when a channel has nonzero skew.SignalReadneeds the same rule asRecord: its wrapper is frozen, but its NumPy values can still be overwritten in place, so the original read cannot tell the writer how the current values are aligned.I considered making
SignalReadarrays read-only so its writer could infer alignment. That would break in-place arithmetic, and NumPy's writable flag can be turned back on, so it would not provide a reliable guarantee. The explicit choice is simpler and consistent across the three writers.