Skip to content

Add a guide for migrating from the legacy API - #829

Merged
tompollard merged 2 commits into
mainfrom
docs-migration-guide
Dec 1, 2026
Merged

tompollard merged 2 commits into
mainfrom
docs-migration-guide

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Add a "Migrating from the legacy API" page to the docs, linked under Other Content. It gathers the old → new mappings that are currently spread through docs/io.rst, the processing docs and the changelog:

  • a before-and-after example reading from PhysioNet and writing a copy;
  • tables for functions, reading arguments, Record attributes, Annotation attributes and processing arguments;
  • how to replace pn_dir with physionet:// paths or complete HTTP URLs;
  • the behaviour differences that matter when switching: strict channel selection, stable result shapes, write-time count checks, merge_annotations's exclusive stop, and read_annotations rejecting record files.

It notes that older names keep working without warnings, apart from pn_dir, and that dl_files has no newer name because physionet.download covers whole-project downloads.

Related to #672.

Checks

  • Every function, argument and attribute named on the page was checked against main.
  • Both examples run as written against live PhysioNet. The legacy one emits the two expected pn_dir FutureWarnings, and the newer one emits none.
  • Sphinx HTML build with warnings as errors: passed.

@tompollard 🟥 red 🦥 sloth · aspen

The new docs page maps the legacy function, argument and attribute names
to the newer ones, shows how to replace pn_dir with physionet:// and HTTP
paths, and lists the behaviour differences that matter when switching.
@tompollard

Copy link
Copy Markdown
Member Author

I found two accuracy issues in the migration guide that I'd fix before merging:

  1. The annotation writer mapping at docs/migration.rst:85–87 misses a changed default. Annotation.wrann() defaults to write_fs=False, while Annotation.write() and write_annotations() default to True. I wrote the same annotation both ways and read it back: the legacy file had fs=None; the newer file had fs=360. Please call this out, and show write_fs=False for anyone who needs the legacy output.
  2. The attribute summary at docs/migration.rst:191–193 implies that MultiRecord has .metadata. It does not: read_record(..., combine_segments=False) returns a MultiRecord without that property. Please say that .metadata belongs to Record, while both record types expose the source-header properties and MultiRecord has .segment_views.

One smaller point: the opening examples read annotations but write only the signal record. Please either write the annotation in both examples or say that the copy contains signals only.

The guide is useful overall. The docs check passes; these are wording and migration-behavior corrections.

@tompollard
tompollard marked this pull request as ready for review December 1, 2026 06:10
Annotation.wrann does not store the sampling frequency by default, while
the newer annotation writers do. MultiRecord has the source properties
and segment_views but no metadata. Both examples now also write the
annotations.
@tompollard

Copy link
Copy Markdown
Member Author

Thanks, all three were right. Fixed in d986164:

  1. Annotation fs default. The wrann row now says that write_annotations and Annotation.write store the sampling frequency by default (write_fs=True), whereas Annotation.wrann does not, and that write_fs=False gives the legacy output. I confirmed it as you described: Annotation.wrann read back with fs=None, Annotation.write with fs=360, and Annotation.write(..., write_fs=False) with fs=None.
  2. MultiRecord properties. The paragraph now says that metadata belongs to Record, that both Record and MultiRecord read from files have source_header, source_signal_header and source_selection, and that MultiRecord has segment_views but not metadata.
  3. Examples. Both now write the annotations as well as the record. The legacy example passes write_fs=True, so the two copies match. I ran both against PhysioNet: each writes 100.hea, 100.dat and 100.atr, and the annotation copies read back with fs=360.

The strict docs build passes.

@tompollard
tompollard merged commit 25f068e into main Dec 1, 2026
19 checks passed
@tompollard
tompollard deleted the docs-migration-guide branch December 1, 2026 06:10
tompollard added a commit that referenced this pull request Dec 1, 2026
## Summary

Start deprecating the legacy function names from #672. Calling one of
these now emits a `DeprecationWarning` that names its replacement:

| Legacy | Use instead |
|---|---|
| `rdrecord`, `rdsamp`, `rdann` | `read_record`, `read_signals`,
`read_annotations` |
| `Record.wrsamp` | `Record.write` |
| `Annotation.wrann` | `Annotation.write` |
| `dl_database`, `get_record_list`, `get_dbs` | `download_records`,
`list_records`, `list_databases` |
| `show_ann_labels`, `show_ann_classes` | `show_annotation_labels`,
`show_annotation_classes` |
| `processing.Comparitor` | `processing.Comparator` |

- **`DeprecationWarning`, not `FutureWarning`:** Python shows it in
scripts, notebooks and test suites, but not by default when the call
comes from another installed package, so users of downstream libraries
aren't flooded. A later release can switch to `FutureWarning` before
removal in a major version.
- **Internal calls stay silent:** the newer functions, `mrgann`, the
processing helpers and plotting still use some legacy implementations
internally without warning.
- **Left silent for now:** names whose replacement doesn't cover every
use: `rdheader` (no replacement for `rd_segments=True`), the
module-level `wrsamp` and `wrann` (which take arrays directly), `mrgann`
and `MultiRecord.wrsamp`; `dl_files` (covered by `physionet.download`);
and the legacy attribute and argument names.
- **Works alongside the `pn_dir` warning:** the helpers now live in
`wfdb.io._deprecation` and are shared with the `pn_dir` decorator. With
two stacked wrappers, each one finds the real caller, so
`rdrecord("100", pn_dir=...)` emits both a `DeprecationWarning` and a
`FutureWarning`, each pointing at the user's line. Python 3.11 is still
supported, so this doesn't rely on `skip_file_prefixes`.
- **`show_ann_labels` and `show_ann_classes`** become thin wrappers
instead of identical aliases. **`Comparitor`** resolves through a module
`__getattr__` in `wfdb.processing` and `wfdb.processing.evaluate`, so
old pickles still load (with a warning). `__all__` keeps `Comparitor` in
star imports of both modules, which warn at the import.
- **Docs and tests:** the migration guide and changelog are updated.
Because many existing tests exercise the legacy names on purpose, pytest
ignores this specific warning message; the new
`tests/test_legacy_deprecations.py` checks the warnings explicitly.

The warning messages refer to the migration guide added in #829.

## Checks

- New tests: each legacy name warns exactly once at the caller's line;
the newer API and internal legacy calls are silent with
`DeprecationWarning` as an error; old `Comparitor` pickles load.
- Checked by hand: a script calling `rdrecord` shows the warning at its
own line, while the same call from an imported library module stays
silent under default filters. `import wfdb` is clean with `-W
error::DeprecationWarning`.
- Offline suite: 1,587 passed, 4 skipped. Ruff check and format, and the
Sphinx build with warnings as errors: passed.

<sub>@tompollard 🟥 red 🦥 sloth · aspen</sub>
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