Skip to content

Switch read_record to RecordData for 6.0 - #924

Merged
tompollard merged 3 commits into
mainfrom
api/record-data-v6
Dec 4, 2026
Merged

tompollard merged 3 commits into
mainfrom
api/record-data-v6

Conversation

@tompollard

Copy link
Copy Markdown
Member

This implements the 6.0 reader decision on #749. The version bump and release remain separate.

Public API changes

  • read_record(...) now returns RecordData, using the selected-read path previously exposed as read_signals(...). Its result has one signal kind and layout, fixed metadata, editable arrays, and source provenance.
  • read_record(..., combine_segments=False) is removed. Use read_segments(...) for the segment view, or rdrecord(..., m2s=False) for a mutable MultiRecord.
  • read_signals, wfdb.SignalRead, and wfdb.io.SignalRead are removed. The wfdb.io.signal_values.SignalRead alias remains so old pickles still load.
  • rdrecord, rdsamp, rdheader, wrsamp, and the mutable Record/MultiRecord remain available. The rdsamp deprecation message now points to read_record.

The README, I/O docs, and migration guide show the new read/write pair and the legacy fallback. Tests that exercise mutable Record behavior now construct it through the retained legacy reader; tests of selected values use read_record.

Parity and verification

  • Added 60 checked-in snapshots generated from the v5.18.0 tag's read_signals. They cover single and multi-segment records, both signal kinds and layouts, selection, skew, masks, conversions, metadata, and provenance. The 6.0 read_record matches them. Four snapshots accept only the metadata/provenance comment change merged in Preserve Unicode and comment text in WFDB headers #923.
  • Old 5.17.0 SignalRead pickle fixtures still load and remain usable.
  • Full offline suite: 2,348 passed, 4 skipped (bxb unavailable), 23 network tests deselected.
  • Ruff check and format pass; Sphinx builds with warnings treated as errors.

This is a breaking change intended for the 6.0 release. The migration guide lists each replacement and keeps the mutable legacy API available.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with read_signals, and regenerated all 60 cases. They're identical to read_record_v5_18.json. The single_format_24 exception covers only the #923 comment change.

  • Parity across the sample data. I ran my two read comparisons with read_signals on 5.18.0 and read_record here:

    • 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 of 310derive_3, n8_evoked_raw_95_F1_R9 and test_generator_2, the three headers whose comments or units #923 corrected. No values or written bytes differ.

  • Nothing still uses the removed API. read_signals and SignalRead now 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 raises TypeError("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_signals and SignalRead: a module __getattr__ in wfdb and wfdb.io raising AttributeError that names read_record and RecordData.
  • Old Record attributes: a RecordData.__getattr__ covering only the known Record names (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 raise AttributeError naming the replacement, for example "use data.signals.values", "data.metadata.fs", "write_record(path, data)", or "use rdrecord for a mutable Record". Every other name must still raise a plain AttributeError, so copy, pickle and hasattr keep 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=[...]).

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the parity against 5.18.0. I addressed the migration feedback in f5cc851.

read_record(..., combine_segments=...) now raises a TypeError pointing to read_segments or rdrecord(..., m2s=False). Accessing the removed public read_signals and SignalRead names, or common mutable Record fields on RecordData, now gives an AttributeError with the replacement. Unknown attributes still give an ordinary AttributeError.

I added the 5.x Record → 6.0 RecordData field mapping to the migration guide and changed the three mutable writer errors to suggest rdrecord. Tests cover the new error messages, including all 18 legacy field names. The full offline suite passes (2,364 passed, 4 skipped), as do Ruff and the docs build.

@tompollard

Copy link
Copy Markdown
Member Author

I fixed both combine_segments details in c0418e4. Passing True now says to remove the argument because read_record already combines segments; False points to read_segments (or legacy rdrecord(..., m2s=False)). The signature and help() now show combine_segments=<removed in 6.0> rather than Ellipsis. I added tests for each message and the displayed signature. Targeted tests, Ruff and the docs build pass.

@tompollard
tompollard merged commit 03ca1ff into main Dec 4, 2026
19 checks passed
@tompollard
tompollard deleted the api/record-data-v6 branch December 4, 2026 21:18
tompollard added a commit that referenced this pull request Dec 4, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant