Repository navigation
Handle missing skew tails in format 8 reads - #913
Conversation
tompollard
left a comment
There was a problem hiding this comment.
This fixes #910, and the expanded-layout change fixes a silent bug in every format. It can merge. I have one suggestion for legacy physical reads and one changelog point. The offline suite (2,196 passed, 4 skipped), Ruff and CI pass.
What I checked
-
Nothing else changes. My comparisons against
main(ceb13f2), 3,520 single-segment calls and 976 multi-segment calls, show zero differences. No sample record has a skewed tail that this touches. -
Format 8 tails. I built a skewed format 8 segment followed by a format 16 segment, as an 8 + 8 frame multi-segment record with skew 2 on the format 8 channel:
Reader mainThis branch read_signals, digitalTypeErrorsegment a's last 2 frames masked, segmentbintactread_segmentsTypeErrorthe same 2 frames masked in entry ardrecord, all forms (single-segment,m2s=True/False)TypeErrorthe new ValueErrorread_recordTypeErrorthe new ValueErrorSo the legacy check covers multi-segment reads too, through the segment reads.
rdrecordofbinformats, which is format 8 without skew, is unaffected.
Changelog: the expanded fix affects all formats
For a skewed channel with several samples per frame, _skew_sig used to mark only nan_replace samples rather than nan_replace × samples_per_frame. The remaining samples of the missing frames came back as unmarked zeros. With a format 16 channel at 2 samples per frame and skew 2, main's rdrecord(..., smooth_frames=False) ends with [..., 16, 0, 0, -32768, -32768], and read_signals masks only the last two. Here all four are marked in both readers.
That's wrong data on main for any format, not only format 8. The entry's last sentence covers it, but it's the more widely relevant fix. I'd make it its own sentence or entry: "Expanded reads of skewed signals with more than one sample per frame previously returned some samples beyond the end of the signal as 0 instead of missing; every sample of each missing frame is now marked, in rdrecord as well as the new readers."
Suggestion: legacy physical reads don't need to fail
rdrecord(path), which is physical by default, now raises "Cannot represent the skewed tail of a format 8 signal in a legacy Record" for the format 8 record above. But a physical Record can represent the tail as NaN, as it does for every other format. Only physical=False lacks a marker. Limiting the error to digital legacy reads, and returning NaN for physical ones, would keep the common case working. That would need a matching change to the message and changelog. It's not a regression, since main raised TypeError here, so it can be a follow-up if you'd rather keep this PR small.
|
Agreed on both points. Legacy physical reads now return NaNs for the unavailable format-8 tail; only digital legacy reads raise I also expanded the changelog to call out the separate bug affecting every format: expanded reads with multiple samples per frame could return zeros for some unavailable samples. The entry now names |
Summary
Fixes #910. A skewed format-8 signal has unavailable samples at the end of an aligned read, but format 8 has no reserved digital missing-sample value. The decoder previously tried to assign
Noneto its integer array and raisedTypeError.rdrecord; raise a clearValueErroronly for digital legacy reads, which cannot represent the missing tail.ignore_skew=Trueremains available for raw data.rdrecord.Checks