Skip to content

Deprecate the legacy function names - #830

Merged
tompollard merged 2 commits into
mainfrom
deprecate-legacy-api
Dec 1, 2026
Merged

tompollard merged 2 commits into
mainfrom
deprecate-legacy-api

Conversation

@tompollard

@tompollard tompollard commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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.

@tompollard 🟥 red 🦥 sloth · aspen

Calling rdrecord, rdsamp, rdheader, rdann, wrsamp, wrann, Record.wrsamp,
Annotation.wrann, dl_database, get_record_list, get_dbs, show_ann_labels,
show_ann_classes or processing.Comparitor now emits a DeprecationWarning
naming the newer function. Calls made by the package itself stay silent.

The warning helpers live in a new wfdb.io._deprecation module, shared with
the pn_dir warning, so stacked wrappers find the real caller: both warnings
are emitted and point at the user's line. show_ann_labels and
show_ann_classes become thin wrappers, and Comparitor resolves through a
module __getattr__ so old pickles still load.
Base automatically changed from docs-migration-guide to main December 1, 2026 06:10
@tompollard
tompollard force-pushed the deprecate-legacy-api branch from a3ec21e to 9d8fbfa Compare December 1, 2026 06:10
@tompollard

Copy link
Copy Markdown
Member Author

Two points I'd address before merging:

  1. Moving Comparitor to module __getattr__ drops it from star imports. I checked from wfdb.processing import * and from wfdb.processing.evaluate import *: both provide Comparitor on main, and neither does on this branch. Since the old name is meant to keep working, please preserve that import form while adding the warning.
  2. Some warning messages suggest replacements that do not cover the old use. rdheader(..., rd_segments=True) returns a mutable MultiRecord with all segment headers; read_header() returns an immutable master header, and read_multi_segment_headers() reads only one channel-defining segment. Likewise, module-level wrsamp() and wrann() accept arrays, while write_record() and write_annotations() require constructed objects. I'd leave those names unwarned until their migration paths are complete, or give specific recipes in the guide and more precise warning text. This is the same reason the PR leaves mrgann unwarned.

The new warning tests pass locally (6 passed), and the warning locations and internal-call suppression look sound.

Star imports of wfdb.processing and wfdb.processing.evaluate provide
Comparitor again, through __all__, and warn when importing it that way.

rdheader and the module-level wrsamp and wrann no longer warn: their
newer counterparts do not cover rd_segments=True or writing directly from
arrays. The guide explains what replaces them and what does not yet.
@tompollard

Copy link
Copy Markdown
Member Author

Thanks, both were right. Fixed in 09c742d:

  1. Star imports. Both wfdb.processing and wfdb.processing.evaluate now define __all__ as their previous public names plus Comparitor, so from wfdb.processing import * and from wfdb.processing.evaluate import * provide Comparitor again, as on main. Importing it that way goes through __getattr__ and warns at the import line. I checked that both star imports now export exactly the same names as main. (evaluate imports warnings as _warnings so it doesn't add a new public name.) New tests cover both modules.
  2. Incomplete replacements. rdheader and the module-level wrsamp and wrann no longer warn, for the reasons you gave: nothing replaces rd_segments=True, and the newer writers need a Record or Annotation rather than arrays. Record.wrsamp and Annotation.wrann still warn, since Record.write and Annotation.write cover them. The guide's table now says what replaces each of these three and what doesn't yet, and lists them with mrgann, dl_files and MultiRecord.wrsamp as not warning. A new test checks they stay silent with DeprecationWarning as an error, including rdheader(..., rd_segments=True).

I also updated the changelog and the PR description. The offline suite (1,590 passed), Ruff and the strict docs build pass.

@tompollard
tompollard merged commit 098ef24 into main Dec 1, 2026
19 checks passed
@tompollard
tompollard deleted the deprecate-legacy-api branch December 1, 2026 06:15
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