Repository navigation
Build multi-segment signal reads from a private model - #900
tompollard wants to merge 2 commits into
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The multi-segment assembler matches main on every sample record, with the pickle fix now covering both paths. It also fixes something the description doesn't mention: on main, read_signals can't read a fixed-layout record that has a null (~) segment. That fix needs one edge case handled, plus a test and a changelog entry. The offline suite (1,988 passed, 4 skipped) and Ruff pass.
What I checked, against main (2151bdc, with #899)
I ran the same script on both versions, covering all six multi-segment records in sample-data, fixed and variable layout:
- windows across the first twelve segment boundaries;
- random windows, full reads where practical, and an empty window;
- reversed channels;
channel_nameswith missing names, with and withoutforce_channels=False;channels=[0]withforce_channels=False;- resolution 16;
- both kinds and both layouts.
That gave 976 calls: 614 reads and 362 expected errors. The errors include the variable-layout digital calibration error and the p000878 segments missing from sample-data. For each read I compared:
- values, masks and dtypes;
- metadata;
- the source headers, selection and segments;
- conversions and every attribute of
to_legacy_record(); - pickle and copies;
- written bytes.
I repeated this after editing the arrays in place.
Everything matches except:
- Pickled provenance now survives on both paths, as the changelog entry says.
- An empty selection. With
force_channels=False, a window where none of the requested channels exist (for examplep000878, frames 0–5) hasto_legacy_record()returningchecksumandinit_valueasNoneinstead of[]. The written bytes are identical. It's harmless, but I mention it because the description says the projection is identical.
To fix: fixed-layout records with a null segment
I built small fixed-layout records with a format 16 segment and a ~ gap, in both orders. On main, almost every read fails with an internal error such as AttributeError: 'NoneType' object has no attribute 'd_signal' or ... 'fmt'. The only exception is a window that avoids the gap entirely. Here they read correctly:
- the gap is NaN (physical) or masked (digital);
- the source segments include the
~entry; to_physical,to_digital,to_legacy_recordandwriteall work;- a write and read round trip returns the same values and masks.
That's a real fix, but two things are missing:
-
A window entirely inside the gap raises a bare
StopIteration. For example,start=600, stop=700on a record whose second segment is~._reference_signalscallsnext(...)without a default when no segment model was loaded. The master already reads the first non-gap segment's header intosignal_header, before the loop. Using its signals as the reference when nothing is loaded would return an all-missing view, consistent with how the gap is handled when the window only partly overlaps. A fixed record made entirely of~segments hits the same unguardednext(...)at the start. That one probably deserves a clearValueError. -
A test and a changelog entry. Please add a fixed-layout gap case to
test_multi_read_model.pycovering:- a window across the gap;
- a window inside the gap;
- a write round trip.
And add a changelog entry, since
read_signalsusers on 5.17 couldn't read these records.
Already on main, for the follow-up list
A format 8 channel has no missing-sample marker. A gap segment in a format 8 multi-segment record therefore fails digital reads with TypeError: int() argument ... 'NoneType', on main and here, in both layouts. fill takes _digi_nan(fmt) and gets None. It belongs with the expanded 999999 issue from #899: both need one rule for missing samples in formats without a marker.
For later, not this PR
To keep parity, the assembler reproduces some legacy behaviour in a modern reader:
raise IndexError("list index out of range")for an empty expanded selection;- a
printwhen no requested channel is present; - a bare
Exceptionfor the variable-layout digital calibration error.
That's the right choice while the comparison path still exists. Once 1c removes it, these should become proper ValueErrors, with a changelog entry, before RecordData makes this the main reader.
|
Thanks for the detailed check. I pushed d80c36e to address the fixed-layout gap case. When a selected window falls entirely inside a I fixed the empty-selection difference too: I agree the format 8 gap needs a separate missing-value rule alongside #899. I'll leave the legacy-shaped errors and print in place for parity here, then clean them up after 1c and before Locally, the offline suite passes (1,994 passed, 4 skipped), as do Ruff and the Sphinx build with warnings treated as errors. |
Summary
This is step 1b of the reader-model work in #744 and #749.
read_signalsnow decodes and flattens fixed- and variable-layout multi-segment records from parsed headers and sample arrays. A normal read no longer constructs segmentRecordobjects, aMultiRecord, or a flattenedRecord. The publicSignalReadresult is unchanged; conversion and writing still create a compatibilityRecordlazily from the current values.The assembler preserves channel selection, per-segment missing-sample masks and storage formats, segment provenance, source headers, and the legacy rule for inconsistent calibration across variable-layout segments. It also avoids reading the master header twice. Zero-length single-segment headers still use the retained fallback; removing that temporary path is step 1c.
This PR includes a changelog entry for the now-complete pickle provenance fix: restored
SignalReadobjects retain source header and selection information for both single- and multi-segment reads.Evidence
main(Build single-segment signal reads from a private model #899): 960 multi-segment read cases, zero differences. Cases cover windows at the first ten segment boundaries, gaps, channel order and name selection, both kinds and layouts, resolutions 16 and 64, and bothforce_channelsvalues. Values, masks, dtypes, metadata, source provenance, conversions, copy, deepcopy, pickle results, and error outcomes were compared.mainand this branch. A separate 16-case comparison of every field onto_legacy_record()also matched.Recordpath for boundaries, variable layout, skewed segments, archives, conversion, masks, and provenance. A test asserts that ordinary multi-segment reads do not call theRecordconstructor path.sample-data/multi-segment/fixed1/v102s, frames 50,000–125,000, 30 measured runs after three warmups, macOS 15.7.3 arm64, Python 3.11.13, NumPy 2.4.6. Median read time versusmainwas 4.8–13.6% lower across physical/digital and uniform/expanded modes. Peak traced Python allocation was unchanged for physical reads and 0.14–0.24 MiB higher for digital masks, with no extra full sample-array copy.Review focus
Please check the variable-layout field reconciliation and the lazy compatibility projection, especially writes after editing masked digital values. The cross-version scripts and benchmark are one-off review aids; the durable parity cases are in
tests/test_multi_read_model.py.