Skip to content

Proposal: readable names for the public API #672

Backlog

Description

@tompollard

Many of the package's public names are abbreviations that need the documentation to interpret: rdrecord, rdann, wrsamp, p_signal, e_d_signal, sampfrom, m2s, return_res, label_store. Slightly longer names would make code easier to read and write, and make the package easier to learn, especially for people who don't know the WFDB C tools these names come from.

Renaming affects everyone's code, tutorials and answers online, so this issue proposes some principles and a list of names to agree on before any code changes.

Principles

  1. Add, don't break. New names are added alongside the old ones, which keep working. Old names are deprecated only later, and removed (if ever) only in a major release.
  2. Use the WFDB format's own terms. Header fields such as adc_gain, adc_res, adc_zero, baseline, skew, byte_offset, checksum, init_value and block_size are named in the WFDB specification, so they stay as they are. Tools that mirror WFDB programs (sampfreq, signame, wfdbdesc, wfdbtime) keep their names too.
  3. Spell out abbreviations, and follow Python conventions: read_/write_ for I/O, start/stop for ranges, plural names for lists and arrays, and n_ for counts.
  4. Rename once. Changes to how files are located (Use a single path argument (and deprecate pn_dir and file_name) #534) and what signal data is returned (Better API for specifying return data of signals #376) should be settled together with the names, so that nothing is renamed twice.

Proposed names

These are a starting point for discussion. The old names would remain as aliases.

Functions and methods

Current Proposed
rdrecord read_record
rdsamp read_signals
rdheader read_header
rdann read_annotations
wrsamp write_record
Record.wrsamp Record.write
wrann write_annotations
Annotation.wrann Annotation.write
mrgann merge_annotations
dl_database download_database
dl_files download_files
get_dbs list_databases
get_record_list list_records
show_ann_labels, show_ann_classes show_annotation_labels, show_annotation_classes
processing.Comparitor processing.Comparator

Arguments

Current Proposed Where
sampfrom, sampto start, stop reading records and annotations
m2s combine_segments rdrecord
return_res dtype (or resolution) rdrecord, rdsamp
rd_segments read_segments rdheader
extension annotator (the WFDB term) rdann, wrann
shift_samps relative_samples rdann
return_label_elements label_fields rdann
pn_dir replaced by physionet:// paths (#534) everywhere
sig signal processing functions
qrs_inds qrs_indices compute_hr and others

Record and annotation attributes

Current Proposed
p_signal, d_signal physical_signals, digital_signals
e_p_signal, e_d_signal expanded_physical_signals, expanded_digital_signals (or folded into #376)
sig_name signal_names
sig_len signal_length
n_sig n_signals
samps_per_frame samples_per_frame
fmt formats
Annotation.label_store Annotation.label_codes
Annotation.aux_note Annotation.notes
Annotation.chan, Annotation.num Annotation.channels, Annotation.numbers
Annotation.ann_len Annotation.n_annotations

How it could be done

  • Functions: the new name is the function, and the old name is an alias.
  • Arguments: a small decorator maps old keyword names to new ones, and raises an error if both are given.
  • Attributes: the new names are the attributes, and the old names are properties that read and write them, so code that sets record.p_signal keeps working. Internal names, such as the header field tables, can change separately or stay.

Release plan:

  1. A minor release adds the new names, and the documentation and examples switch to them. The old names are listed as aliases, with no warnings.
  2. A later release warns when old names are used. One question below is whether that should be a DeprecationWarning or a FutureWarning.
  3. A major release decides whether the old names are removed or kept as aliases for good.

Questions

  1. Should fs stay, as in SciPy, or become sampling_frequency?
  2. start/stop, or start/end? stop matches Python's range and slicing, where the stop is excluded, as sampto now is for both signals and annotations.
  3. Should the processing functions be renamed in the same pass, or separately?
  4. Is it worth renaming rdsamp at all, or should it be deprecated in favour of read_record, which returns the same data and more?
  5. How long should the old names keep working without warnings?

Related: #371 (record metadata), #376 (returned signal data), #500 (reading and writing that match), #534 (a single path argument).

Activity

  1. tompollard commented on Nov 24, 2026

    @tompollard
    MemberAuthor

    @briangow please could you add your thoughts on the proposed names above?

  2. tompollard commented on Nov 24, 2026

    @tompollard
    MemberAuthor

    Related: #534 now has a proposed plan for phasing out pn_dir in favour of physionet:// paths in the first argument. If that argument is renamed here (for example to path), the two changes should go together.

  3. briangow commented on Nov 24, 2026

    @briangow
    Contributor

    @tompollard , I agree that it would be ideal to have readable names but I also think there is some benefit around keeping the naming consistent with the C package. Consistency in specification and naming between Python and C would be ideal.

    I don't see any major issues with your proposed names and I agree that the old variables would need to be supported for some time before being phased out.

    For your questions:

    1. I personally think fs is so common in signal processing terminology that I'd leave it as-is.
    2. I might expand these either way since start / stop / end don't make it clear that these are sample numbers (whereas sampto implies that).
    3. Again would be great if we could come up with a way to update C and Python in-sync. To answer the question, I'd probably separate the updates that most users will see from backend updates.
    4. I would continue to support it for backward compatibility, even if it isn't used as often as rdrecord.
    5. Would be nice to involve the community in questions like this. I don't think Python is as embedded in commercial / standardized implementations as C is (e.g. DWC to WFDB conversion) but it would be good to know if we will break things.
  4. tompollard commented on Nov 25, 2026

    @tompollard
    MemberAuthor

    Thanks Brian!

    I personally think fs is so common in signal processing terminology that I'd leave it as-is.

    👍

    I might expand these either way since start / stop / end don't make it clear that these are sample numbers (whereas sampto implies that).

    start and stop seem cleaner and more memorable to me, but we can discuss. for me, sampto belongs with some of the other slightly obscure names.

    Again would be great if we could come up with a way to update C and Python in-sync. To answer the question, I'd probably separate the updates that most users will see from backend updates.

    I agree, but I'm not sure it's realistic to keep them in sync. I think what we can do is come up with a clear spec for the software at https://github.com/wfdb/wfdb-spec. We can then document level of coverage for different implementations.

    I would continue to support it for backward compatibility, even if it isn't used as often as rdrecord.

    Yep, this is easy enough to do.

    Would be nice to involve the community in questions like this. I don't think Python is as embedded in commercial / standardized implementations as C is (e.g. DWC to WFDB conversion) but it would be good to know if we will break things.

    I agree. We can do this in a small way by having the conversations here - there are a large-ish number of people watching the repo.

    I'd like to start regular working group meetings too, but don't want to hold up progress for what (I think) are fairly clear improvements.

  5. tompollard commented on Nov 25, 2026

    @tompollard
    MemberAuthor

    @cbrnr @TheNetherWatcher @Ivorforce any thoughts on the proposal above to introduce friendlier names for the public API?

  6. cbrnr commented on Nov 25, 2026

    @cbrnr
    Collaborator

    I like it! I would also leave fs as it is common enough (FWIW, MNE-Python uses sfreq, which I don't really like as it is less common).

    If the entire package is based on samples, I think start/stop/end are better than the old names.

    I cannot say much on keeping names consistent with C other than users will probably not use both versions; it is likely that most users will only ever use one language, and for Python I definitely prefer the new names.

    I would continue supporting the old names for several releases, but start warning soon (FutureWarning), and eventually remove the old names. It's just easier to support and maintain, and I guess we want people to switch over.

  7. tompollard commented on Nov 25, 2026

    @tompollard
    MemberAuthor

    Thanks @cbrnr!

    I would also leave fs as it is common enough (FWIW, MNE-Python uses sfreq, which I don't really like as it is less common).

    Your and @briangow’s comments make a good case for keeping fs. I still lean toward sampling_frequency for the new API because it’s immediately clear to new users, and we’re already introducing aliases for other names. Is there a reason beyond familiarity to prefer fs?

  8. cbrnr commented on Nov 25, 2026

    @cbrnr
    Collaborator

    No, sampling frequency is perfectly fine and the most common term, although sampling rate is equally common and shorter.

  9. TheNetherWatcher commented on Nov 25, 2026

    @TheNetherWatcher
    Contributor

    Thanks for the ping, the proposal reads well to me. A few thoughts:

    fs: I'd keep it. It's probably the attribute people use most, and it usually goes straight into SciPy (signal.butter(..., fs=record.fs)), so it's already familiar to anyone doing signal processing. If we do rename it, I agree with @cbrnr that sampling_rate is better than sampling_frequency. It's shorter, and NeuroKit2 uses it, which a lot of wfdb users already work with.

    start/stop: +1 for stop. It matches range and slicing, and since sampto is already exclusive, nothing changes in behaviour.

    Warnings: FutureWarning. DeprecationWarning is hidden by default unless it's triggered in __main__, so most users running scripts or notebooks through other modules wouldn't see it until the names are gone.

    rdsamp fields dict: one thing I don't see in the list. rdsamp returns a dict with keys like fs, sig_name, sig_len, n_sig and units. If the attributes become signal_names / n_signals but read_signals still returns the old keys, the two will disagree. We should either rename the keys too (keeping the old ones for a while) or decide this together with #376, since the return type might change anyway.

    aux_note → notes: this seems to go against principle 2, since the spec calls it the aux string. Maybe aux_notes, or keep aux_note?

    return_res: I'd go with dtype over resolution. People already think in numpy dtypes, and it says what you get back.

    Happy to pick up parts of the implementation once the names are settled (the argument-alias decorator, for example).

  10. tompollard commented on Nov 25, 2026

    @tompollard
    MemberAuthor

    thanks @TheNetherWatcher!

    fs: I'd keep it. It's probably the attribute people use most, and it usually goes straight into SciPy

    Sounds like I am in the minority on this one - let's keep fs.

    Happy to pick up parts of the implementation once the names are settled (the argument-alias decorator, for example).

    Thanks, I appreciate the offer. It's probably easiest for me to take on the refactor in one go, and then perhaps I'll ping you for a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions