Repository navigation
Preserve source header and selection on loaded reads - #762
Conversation
tompollard
left a comment
There was a problem hiding this comment.
I found two issues with the new read provenance:
-
The retained source header can differ from the file (
src/wfdb/io/record.py:2803-2810, 3010). When a header omitssig_len, the read path replaces it with an inferred length before attaching it as_read_source.header. Forsample-data/100-no-len,rdheader().sig_lenisNone, whilerdrecord()._read_source.header.record_fields.sig_lenis650000. If this field is meant to preserve the parsed source header, keep the original header there and use a separate effective copy for reading and caching. -
The new field changes pickle compatibility (
src/wfdb/io/record.py:2450-2458, 3010). A record pickled by this branch cannot be loaded by the PR's base version: it raisesAttributeError: Can't get attribute '_ReadSource'. If saved records need to survive a downgrade or move to an older installation, exclude this private provenance from the serialized state. If cross-version pickle compatibility is outside the contract, this is a limitation to document rather than a blocker.
The full offline suite passed (923 passed, 4 skipped, 21 deselected).
|
Thanks, I fixed both points in b2a4ee3.
The full offline suite passes (926 passed, 4 skipped, 21 deselected), as do the docs build and Ruff checks. I also updated the PR description. |
tompollard
left a comment
There was a problem hiding this comment.
The update addresses both points from my previous review: an omitted source sig_len stays unset in _read_source.header, and ordinary Record and MultiRecord pickles load with the base version.
I found one new serialization regression in BaseRecord.__getstate__ (src/wfdb/io/record.py:273-277). Returning only self.__dict__ drops slot state from subclasses. A Record subclass with __slots__ = ("tag",) and tag = "kept" retains tag after a pickle roundtrip on the base commit, but loses it on this branch. copy.deepcopy also loses it. Please preserve the default slot state and remove _read_source only from the dictionary portion.
The affected offline tests pass (223 passed, 14 deselected).
|
Good catch. I fixed this in 44f4f02. I added a |
Summary
Keep the parsed source header and requested source coordinates on records returned by
rdrecord, including flattened and segment-preserving multi-segment reads. The new_read_sourcefield is private. It holds the source header, frame range, and selected channel indices; it is not a second mutable copy of the returned record's metadata.Parsed header comments are now tuples, making the cached source header immutable throughout. Editing the returned
RecordorMultiRecordmetadata does not change that source description. The cache keeps the original parsed header separate from an effective copy when a missing signal length must be inferred, so_read_source.headerstill records the omission.Record equality continues to compare record contents rather than read provenance. Private read provenance is omitted from pickle state so records saved with this branch can still be loaded by the PR base version. The pickle implementation preserves slot state on user-defined
Recordsubclasses.This prepares the source-versus-selection contract in #743 without adding a public API yet.
Checks
git diff --checkpassed.