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
Decouple I/O internals from dynamic Record fields #749
The header field tables, parser, validation, conversion, and writer access record fields dynamically. Parsing assigns fields with setattr, and Record and Annotation equality inspect instance dictionaries. Introducing nested metadata or signal objects can therefore change equality, serialization, and legacy field edits even if read/write results look the same.
Decisions to make
What internal schema should own record, signal, and segment fields during the transition?
Which legacy mutations and object serialization behaviors must be preserved, including in-place edits to list fields?
How should parsing, validation, and writing consume the new schema while keeping warnings out of internal calls?
How should tests distinguish structural equality from equivalent signal data produced through different read paths?
The writer refactor now has a private model with no Record encoder inheritance. It converts a mutable Record from its current fields at the write boundary, and the 5.17.0 byte fixtures, independent comparisons on #898, and the 30-run benchmark on #866 support that boundary. The remaining dependency is on the read side: read_signals still calls read_record, then wraps the returned Record; SignalRead retains a hidden _record for conversion and provenance.
My recommendation is:
Make one private selected-read model. Build it from the parsed header, selected channels/frames, and decoded arrays. It should own the selected channel metadata, calibration, kind, layout, missing-sample representation, alignment, and immutable source provenance. SignalRead conversion and writing should use those fields directly, with no retained Record. A legacy Record can be projected at one compatibility boundary when requested. When a mutable Record is written, continue converting its current fields at write time; never rely on a model saved when it was read.
Use SignalRead as the one modern selected-read result. It already represents exactly one kind and layout and carries masked digital values. Once the private reader model proves it can preserve the existing cases, I would have combined read_record reads return that same result rather than introduce another selected-result class. rdrecord should keep returning mutable Record/MultiRecord. A separate segmented reader should handle uncombined multi-segment access before changing read_record(combine_segments=False); that is a different shape of data. This is a public return-type change, so it needs its own PR and clear migration examples.
Keep Record as the mutable compatibility view. Its public list edits, equality/serialization behavior, and methods remain. Do not put a second mutable metadata object beside those fields. The modern model can be immutable at the metadata level while the signal arrays remain editable; skewed writes still require an explicit signal_alignment because an editable array does not prove its history.
I would start with a private reader-model PR that changes no public return type. It should cover single and multi-segment reads, channel selection/reordering, variable layouts, expanded and uniform values, missing samples, skew, conversions, copy/pickle, provenance, and source-header defaults. Check selected values and masks against current read_record/read_signals, and measure allocations so the reader does not add a full array copy. Only then switch the public result, with the migration guide and tests in that PR. The channel ownership details are in #744.
I want to correct one part of my proposal above. Changing only combined read_record calls to return SignalRead would leave its return type dependent on combine_segments, and would make read_record and read_signals largely redundant.
I would keep distinct roles instead:
read_record returns a mutable Record for callers who need to edit its fields or values and write it again. It has modern source and selection arguments, but the result is deliberately the mutable compatibility object.
read_signals returns SignalRead: one selected kind and layout, immutable metadata, and editable signal arrays.
Uncombined segment access should move to a separate reader. Once that exists, remove combine_segments=False from the modern read_record API so its return type is stable. Keep rdrecord's legacy Record/MultiRecord behavior.
That gives the two public views a reason to exist without adding a third selected-result type. It does not change the private-model goal: read_signals should build its result from the shared private read model, without retaining a hidden Record; read_record should project a mutable Record from the model when requested. Legacy writes still convert the Record's current fields at write time.
For the first PR I would keep public returns unchanged and compare the old and new read paths temporarily. The checks need header-only reads, index and name-based channel selection (including missing_channels), converted views, copy/pickle, variable-layout segments, masks, skew, and allocations on multi-segment flattening. I would not switch the public return contract in that PR.
I agree we should choose the best modern API first, then plan the migration. I am revising my earlier suggestion to keep both modern readers.
read_record should be the one modern reader for a selected record. It should always return the same result type. I suggest RecordData for that class: it contains signal values, channel and timing metadata, and source provenance. read_signals should be retired because it currently returns essentially that same record view under a narrower name.
write_record should accept RecordData, so the pair is obvious. Uncombined segment access belongs in a separate reader, rather than making read_record's type depend on combine_segments.
rdrecord and mutable Record remain the compatibility path. Modern metadata and structure changes should use validated operations that return a new RecordData, such as channel selection, metadata correction, and time shifting. Writing from new arrays is already covered by write_signals.
Two constraints matter for the edit API. The signal arrays can remain editable, but direct NumPy edits can still change their shape, masks, or alignment without going through our methods. write_record must therefore keep preflight checks for array shape, missing samples, range, and explicit alignment where skew requires it; it cannot blindly trust a RecordData. Also, gain and baseline are not merely file-format choices for digital values: they define the values' physical meaning. A calibration-changing operation must say whether it rescales digital samples or reinterprets them. For physical values, choosing gain/baseline at write time can be an encoding choice.
The first PR can stay private and preserve all public returns. It should build and compare the selected read model, reuse or map directly to the existing ChannelMetadata classes, and measure allocations on flattened multi-segment reads. We can make the public naming/return change and the validated edit methods in later focused PRs, with migration notes before release.
Activity
Pin public I/O behavior before record refactor (#750)
Make Record equality return False for unequal signal arrays (#751)
Represent parsed single and multi-segment headers separately (#753)
Keep parsed segment names and lengths together (#759)
Keep multi-segment read selections together (#760)
Type parsed record-line metadata (#761)
Capture channel metadata once for record writes (#838)
Project parsed headers into records explicitly (#839)
Use on-demand channel views for record selection (#840)
Separate current storage fields from logical metadata (#841)
Use a channel snapshot throughout header writes (#845)
Calculate channel defaults from one snapshot (#847)
Use one channel snapshot for header and signal writes (#848)
Expose grouped current channel metadata (#850)
Remove temporary writer parity implementations (#898)
tompollard commentedon Dec 3, 2026
Proposed read-model direction after #866
The writer refactor now has a private model with no
Recordencoder inheritance. It converts a mutableRecordfrom its current fields at the write boundary, and the 5.17.0 byte fixtures, independent comparisons on #898, and the 30-run benchmark on #866 support that boundary. The remaining dependency is on the read side:read_signalsstill callsread_record, then wraps the returnedRecord;SignalReadretains a hidden_recordfor conversion and provenance.My recommendation is:
SignalReadconversion and writing should use those fields directly, with no retainedRecord. A legacyRecordcan be projected at one compatibility boundary when requested. When a mutableRecordis written, continue converting its current fields at write time; never rely on a model saved when it was read.SignalReadas the one modern selected-read result. It already represents exactly one kind and layout and carries masked digital values. Once the private reader model proves it can preserve the existing cases, I would have combinedread_recordreads return that same result rather than introduce another selected-result class.rdrecordshould keep returning mutableRecord/MultiRecord. A separate segmented reader should handle uncombined multi-segment access before changingread_record(combine_segments=False); that is a different shape of data. This is a public return-type change, so it needs its own PR and clear migration examples.Recordas the mutable compatibility view. Its public list edits, equality/serialization behavior, and methods remain. Do not put a second mutable metadata object beside those fields. The modern model can be immutable at the metadata level while the signal arrays remain editable; skewed writes still require an explicitsignal_alignmentbecause an editable array does not prove its history.I would start with a private reader-model PR that changes no public return type. It should cover single and multi-segment reads, channel selection/reordering, variable layouts, expanded and uniform values, missing samples, skew, conversions, copy/pickle, provenance, and source-header defaults. Check selected values and masks against current
read_record/read_signals, and measure allocations so the reader does not add a full array copy. Only then switch the public result, with the migration guide and tests in that PR. The channel ownership details are in #744.tompollard commentedon Dec 3, 2026
I want to correct one part of my proposal above. Changing only combined
read_recordcalls to returnSignalReadwould leave its return type dependent oncombine_segments, and would makeread_recordandread_signalslargely redundant.I would keep distinct roles instead:
read_recordreturns a mutableRecordfor callers who need to edit its fields or values and write it again. It has modern source and selection arguments, but the result is deliberately the mutable compatibility object.read_signalsreturnsSignalRead: one selected kind and layout, immutable metadata, and editable signal arrays.combine_segments=Falsefrom the modernread_recordAPI so its return type is stable. Keeprdrecord's legacyRecord/MultiRecordbehavior.That gives the two public views a reason to exist without adding a third selected-result type. It does not change the private-model goal:
read_signalsshould build its result from the shared private read model, without retaining a hiddenRecord;read_recordshould project a mutableRecordfrom the model when requested. Legacy writes still convert theRecord's current fields at write time.For the first PR I would keep public returns unchanged and compare the old and new read paths temporarily. The checks need header-only reads, index and name-based channel selection (including
missing_channels), converted views, copy/pickle, variable-layout segments, masks, skew, and allocations on multi-segment flattening. I would not switch the public return contract in that PR.tompollard commentedon Dec 3, 2026
I agree we should choose the best modern API first, then plan the migration. I am revising my earlier suggestion to keep both modern readers.
read_recordshould be the one modern reader for a selected record. It should always return the same result type. I suggestRecordDatafor that class: it contains signal values, channel and timing metadata, and source provenance.read_signalsshould be retired because it currently returns essentially that same record view under a narrower name.write_recordshould acceptRecordData, so the pair is obvious. Uncombined segment access belongs in a separate reader, rather than makingread_record's type depend oncombine_segments.rdrecordand mutableRecordremain the compatibility path. Modern metadata and structure changes should use validated operations that return a newRecordData, such as channel selection, metadata correction, and time shifting. Writing from new arrays is already covered bywrite_signals.Two constraints matter for the edit API. The signal arrays can remain editable, but direct NumPy edits can still change their shape, masks, or alignment without going through our methods.
write_recordmust therefore keep preflight checks for array shape, missing samples, range, and explicit alignment where skew requires it; it cannot blindly trust aRecordData. Also, gain and baseline are not merely file-format choices for digital values: they define the values' physical meaning. A calibration-changing operation must say whether it rescales digital samples or reinterprets them. For physical values, choosing gain/baseline at write time can be an encoding choice.The first PR can stay private and preserve all public returns. It should build and compare the selected read model, reuse or map directly to the existing
ChannelMetadataclasses, and measure allocations on flattened multi-segment reads. We can make the public naming/return change and the validated edit methods in later focused PRs, with migration notes before release.