Repository navigation
Reject new skew when writing aligned signals - #842
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. This fixes the reported case and a quieter one: on main, changing 100skew's channel 1 skew from 3 to 2 writes a readable file whose channel 1 is shifted by 2; here both that and the skew[0] = 1 case are rejected before any file is written. Retained and cleared source skew and channels=[1] reads write as before. The offline suite, Ruff and the strict docs build pass locally.
Two things I'd change:
- Manual channel removal. Dropping channel 1 from
d_signaland every per-channel list (withn_sig=1) writes correctly onmain(skew[None]), but now raises "skew and applied source skew have different channel counts". The existing channel-count error says updatingn_sigand per-channel fields together is supported. When the lengths differ, could_skew_for_writeaccept the write if every remaining skew isNoneor 0, and otherwise raise an error pointing toread_record(..., channels=[...])? - Error message. "provide unaligned signal values" doesn't help: replacing
d_signalwith the values from anignore_skew=Trueread still raises, because_applied_skewis still set. Suggestingignore_skew=Truewhen reading would point to the route that works.
Possible follow-ups, both already on main: putting unaligned values into an aligned record while keeping its skew writes without skew, so the data is misaligned; and setting a new skew after an ignore_skew=True read still writes a file that fails to read (could not broadcast input array from shape (14,) into shape (12,)).
|
Thanks, I addressed both points in 0e62fab.
I added tests for both paths. The full offline suite passes (1,627 passed, 4 skipped), as do Ruff and the strict docs build. I agree the two remaining provenance cases are real. I filed them as #843 so we can define the array-replacement and new-skew behavior separately from this fix. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, 0e62fab covers both. A record reduced by hand to channel 0 now writes without skew through both write_record and wrsamp, a remaining nonzero skew gets the clearer read_record(..., channels=[...]) error, and the changed-skew message points to ignore_skew=True, which preserves [None, 3] and reads back correctly. Thanks for filing #843 for the remaining cases. The offline suite, Ruff and the strict docs build pass locally.
Ready to merge once CI is green.
Problem
Writing a record whose source skew was already applied can produce an unreadable file after a partial skew edit. I reproduced this with
read_record("sample-data/100skew", stop=12, kind="digital"), settingskew[0] = 1, then callingRecord.write(): writing succeeds, but reading the result raises a NumPy broadcasting error.wrsamp()previously omitted skew only when the entire current list matched_applied_skew.Change
Both
Record.write()andRecord.wrsamp()now reject a new nonzero skew on already aligned values before creating files. Retained or cleared source skew still writes aligned values without skew in the output header. Manually reducing a record to channels with no remaining skew is allowed; a remaining nonzero skew with no reliable mapping to the original channels gets a clear error suggestingread_record(..., channels=[...]). Reads made withignore_skew=Trueretain their existing behavior, and header-onlywrheader()still writes the declared skew.The previous test that expected a newly assigned skew in the header is updated to check the early error. New tests cover
Record.write(), no partial files, a round trip after clearing one channel's skew, and both safe and unsafe manual channel removal. The change has a changelog entry.Verification
Full offline suite: 1,627 passed, 4 skipped, 23 deselected. Ruff and the strict Sphinx build pass.
Refs #744.