Skip to content

Reject shortened raw skew reads before writing - #846

Merged
tompollard merged 1 commit into
mainfrom
fix/partial-skew-write
Dec 2, 2026
Merged

tompollard merged 1 commit into
mainfrom
fix/partial-skew-write

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

A shortened ignore_skew=True read includes only the requested raw frames.
If a selected channel has positive skew, writing those frames with the source
skew loses aligned values at the end of the view. Both Record.write() and
Record.wrsamp() now reject that write before creating files. The same check
applies through SignalRead.write().

The read records whether its stop is before the source record's end and a
selected channel has nonzero skew. That small private flag survives copying
and pickling. Full raw reads, selected channels without skew, and short reads
whose skew is deliberately cleared remain writable. The legacy test that
previously accepted a short raw skewed SignalRead.write() is updated to
expect the early error; a full-length raw write is still tested.

This addresses the selected-read tail case noted on #843. The separate
question of how to declare the alignment of an arbitrary replacement array
remains open there.

Validation

  • Offline suite: 1,657 passed, 4 skipped, 23 network tests deselected.
  • Ruff check and format pass.
  • Sphinx builds with warnings treated as errors.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. On main, writing the first 100 frames of 100skew read with ignore_skew=True reads back with -2048 in the last three frames of channel 1 (the source has 985, 987, 987), so rejecting it is right. A raw read that runs to the end (start=649000) still writes and reads back identically, and ignore_skew=True reads of headers without a signal length still work, including a skewed one, where the flag is set correctly. The offline suite, Ruff and the strict docs build pass locally.

A possible follow-up rather than a change here: the reader could include the extra max(skew) samples after stop for an ignore_skew=True read, which would make short raw reads writable instead of rejected.

Ready to merge once CI is green.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the reproducer and the edge cases. I agree that reading the extra tail samples could eventually let us write a shortened raw view while preserving its alignment. We would need to define how those extra samples relate to the requested stop and the returned view, so I would handle that separately under #843. This PR keeps the write guard focused on the data the reader returns today.

The CI jobs have passed except for the macOS Python 3.15 job, which is still running.

@tompollard
tompollard merged commit 7b7c444 into main Dec 2, 2026
19 checks passed
@tompollard
tompollard deleted the fix/partial-skew-write branch December 2, 2026 05:12
tompollard added a commit that referenced this pull request Dec 2, 2026
## Summary

- Capture the per-channel fields once before calculating header
defaults, so defaults and the subsequent write use the same current
channel values.
- Validate channel list types and lengths before applying defaults.
Invalid lists now fail without leaving a partially defaulted record.
- Keep the existing mutable `Record` lists as the source of truth;
supplied lists retain their identity and partial lists are not filled
in.

This is a small step toward #749 and #744. It does not change the public
record model.

## Verification

- Offline suite: 1,650 passed, 4 skipped, 23 deselected.
- Ruff format and lint checks passed.
- Strict Sphinx docs build passed.
- Compared six representative generated headers against `main`; all were
byte-identical.

This PR is independent of #846.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant