Repository navigation
Switch read_record to RecordData for 6.0 - #924
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The switch preserves behaviour exactly: 6.0's read_record returns what 5.18.0's read_signals did, apart from the header text #923 intentionally changed. I have no correctness concerns. Because this is the breaking release, though, I'd spend a little more on what people see when their 5.x code breaks. There are also three stale error messages to fix. The offline suite (2,348 passed, 4 skipped), Ruff and CI pass.
What I checked
-
The fixture is a real 5.18.0 snapshot. I checked out
v5.18.0, ran this branch's snapshot code withread_signals, and regenerated all 60 cases. They're identical toread_record_v5_18.json. Thesingle_format_24exception covers only the #923 comment change. -
Parity across the sample data. I ran my two read comparisons with
read_signalson 5.18.0 andread_recordhere:- every single-segment header (3,520 calls);
- the multi-segment records, with windows across boundaries (976 calls).
Both cover values, masks, metadata, provenance, conversions,
to_legacy_record(), pickle and copies, and written bytes, with in-place edits. The multi-segment run is identical. In the single-segment run, the only differences are the metadata and provenance text of310derive_3,n8_evoked_raw_95_F1_R9andtest_generator_2, the three headers whose comments or units #923 corrected. No values or written bytes differ. -
Nothing still uses the removed API.
read_signalsandSignalReadnow appear only in the migration guide and the pickle alias.
Suggested: make the breaking changes explain themselves
This is what 5.x code sees on this branch:
| Code | Result |
|---|---|
read_record(p, layout="uniform", combine_segments=False) |
TypeError: read_record() got an unexpected keyword argument 'combine_segments' |
wfdb.read_signals, wfdb.SignalRead |
AttributeError: module 'wfdb' has no attribute ... |
rec = read_record(...), then rec.p_signal, rec.fs, rec.sig_name, rec.n_sig, rec.sig_len, rec.units, rec.wrsamp() |
AttributeError: 'RecordData' object has no attribute ... |
The last row will be the most common break in 6.0, because read_record was the recommended 5.x reader. Each of these could name its replacement cheaply:
combine_segments: keep it as a parameter that raisesTypeError("read_record no longer accepts combine_segments in 6.0; use read_segments(...) for uncombined segments, or rdrecord(..., m2s=False) for a mutable MultiRecord").read_signalsandSignalRead: a module__getattr__inwfdbandwfdb.ioraisingAttributeErrorthat namesread_recordandRecordData.- Old
Recordattributes: aRecordData.__getattr__covering only the knownRecordnames (p_signal,d_signal,e_p_signal,e_d_signal,fs,sig_name,n_sig,sig_len,units,adc_gain,baseline,fmt,comments,base_date,base_time,wrsamp,adc,dac). It would raiseAttributeErrornaming the replacement, for example "usedata.signals.values", "data.metadata.fs", "write_record(path, data)", or "userdrecordfor a mutableRecord". Every other name must still raise a plainAttributeError, socopy,pickleandhasattrkeep working.
These could follow in a separate PR before the 6.0 release, but they belong with this change.
Migration guide: the most common change is missing
The "Record attributes" table maps old Record names to new Record names. It doesn't show the 5.x read_record user how to read the same things from RecordData. A short table for that, with the rdrecord fallback, would cover most migrations:
5.x Record from read_record |
6.0 RecordData |
|---|---|
p_signal / d_signal |
signals.values, in the requested kind |
e_p_signal / e_d_signal |
signals.values with layout="expanded" |
fs, n_sig, sig_len |
metadata.fs, metadata.n_signals, metadata.n_frames |
sig_name, units |
[s.name for s in metadata.signals], [s.units for s in metadata.signals] |
| assigning to fields | with_channels, with_comments, with_calibration, shift_time, select, with_values |
rec.wrsamp() |
write_record(path, data) or data.write(path) |
To fix: stale advice in three Record writer errors
record.py:5181, 5203 and 5282 tell Record users to select channels with read_record(..., channels=[...]). Those errors come from writing a mutable Record, and in 6.0 read_record returns RecordData, so the advice should be rdrecord(..., channels=[...]).
|
Thanks for checking the parity against 5.18.0. I addressed the migration feedback in f5cc851.
I added the 5.x |
|
I fixed both |
## Summary Prepare wfdb 6.0.0 from merged #923 and #924. This bumps the package version, collects both changelog fragments, and puts the `read_record` return-type change at the top of the release notes. The migration guide from #924 remains the reference for changing 5.x calls. The demo notebook now runs against the 6.0 API: it uses `read_record(..., layout=...)`, accesses `RecordData.signals` and `metadata`, and uses `read_segments` for uncombined segments. Its `plot_wfdb` examples convert to a legacy `Record` because that plotting function still expects one. ## Breaking changes - `read_record` now returns `RecordData`; use `rdrecord` for mutable `Record` or `MultiRecord` objects. - `read_signals` and the public `SignalRead` aliases are removed. Use `read_record` and `RecordData`. - Use `read_segments` for uncombined segments. `read_record` always combines them. - Header decoding and comment parsing preserve text that earlier releases could drop or alter (#923). See the release notes for the UTF-8 and Latin-1 behavior. The legacy API remains available in 6.0. This PR does not tag or publish the release. ## Checks - Offline tests: 2,371 passed, 4 skipped, 23 network tests deselected. - Ruff check and format check passed. - Sphinx documentation built with warnings as errors. - Every offline code cell in `demo.ipynb` ran successfully with the 6.0 API. - `uv build` produced `wfdb-6.0.0.tar.gz` and `wfdb-6.0.0-py3-none-any.whl`; the wheel metadata reports version 6.0.0. After this PR is merged and CI passes, publish a `v6.0.0` GitHub release from the merge commit. The publish workflow will then build from that tag and upload to PyPI.
This implements the 6.0 reader decision on #749. The version bump and release remain separate.
Public API changes
read_record(...)now returnsRecordData, using the selected-read path previously exposed asread_signals(...). Its result has one signal kind and layout, fixed metadata, editable arrays, and source provenance.read_record(..., combine_segments=False)is removed. Useread_segments(...)for the segment view, orrdrecord(..., m2s=False)for a mutableMultiRecord.read_signals,wfdb.SignalRead, andwfdb.io.SignalReadare removed. Thewfdb.io.signal_values.SignalReadalias remains so old pickles still load.rdrecord,rdsamp,rdheader,wrsamp, and the mutableRecord/MultiRecordremain available. Therdsampdeprecation message now points toread_record.The README, I/O docs, and migration guide show the new read/write pair and the legacy fallback. Tests that exercise mutable
Recordbehavior now construct it through the retained legacy reader; tests of selected values useread_record.Parity and verification
read_signals. They cover single and multi-segment records, both signal kinds and layouts, selection, skew, masks, conversions, metadata, and provenance. The 6.0read_recordmatches them. Four snapshots accept only the metadata/provenance comment change merged in Preserve Unicode and comment text in WFDB headers #923.SignalReadpickle fixtures still load and remain usable.bxbunavailable), 23 network tests deselected.This is a breaking change intended for the 6.0 release. The migration guide lists each replacement and keeps the mutable legacy API available.