Repository navigation
Description
The modern API (read_record, read_signals, write_record, read_annotations, download_records, and related names) is still new. Changes that would be breaking later are cheap now. This issue collects the changes worth considering before the new names settle, roughly from largest to smallest.
1. Choose one modern data model
The modern API currently has two result types for the same data:
read_recordreturns a mutableRecord.read_signalsreturns a frozenSignalRead, although its arrays are still mutable.
To write a Record correctly after edits, the writer has to infer what happened since the read from private state: _applied_skew, _read_skew, _incomplete_skew_tail and _read_source. #843, #844, #846, #849 and #850 were all spent keeping that state accurate.
If the modern path used immutable values plus metadata, alignment and other read facts would be part of the data instead of being inferred from it. Record could remain the legacy compatibility type. This is the question #744 and #749 are working towards, so it should be decided before more snapshot work.
2. A modern way to write new data from arrays
The most common write is "I have a NumPy array; save it as a WFDB record." Today that needs either the module-level wrsamp, or wfdb.Record(...), which has 39 constructor parameters. docs/migration.rst notes that wrsamp doesn't emit a deprecation warning because no replacement covers this case, so the legacy writers can't be removed until one exists.
For example, something like:
wfdb.write_record(path, values, fs=360, names=["MLII", "V5"], units=["mV", "mV"])Storage format, gain and baseline would be chosen automatically unless given.
3. Remove legacy parameters from new functions
pn_diralready emits aFutureWarning, andphysionet://URIs work. New functions shouldn't launch with a deprecated parameter. Remove it from the modern functions outright.download_records(records="all")uses a string placeholder for "all records", the pattern we chose not to carry over fromdl_database. UseNonefor all records, and dropverboseprinting in favour of the returned list.- Channel selection uses four parameters:
channels,channel_names,force_channelsandmissing_channels.channelscould accept indices or names, withmissing_channelsas the policy for absent names, andforce_channelsremoved.
4. Use the same words for reading and writing
read_record(ignore_skew=True)andwrite_record(signal_alignment="raw")describe the same concept with different words. Usingsignal_alignment="aligned" | "raw"on both sides would be clearer, especially if Define skew provenance when signal values or skew are edited before writing #843 makes the choice required when writing skewed records.read_signalsrequireslayout, whileread_recorddefaults it to"uniform". These should be consistent.
5. One return type per function
read_record(combine_segments=False) returns a MultiRecord; otherwise it returns a Record. Segment-level access already has its own types (SegmentView, read_multi_segment_headers), so read_record could always return a single type.
6. Represent invalid samples clearly
Physical reads represent invalid samples as NaN. Digital reads use a placeholder value that depends on the storage format, such as -2048 for format 212, so callers need to know format details to find them. A per-channel invalid_value in the metadata, or a mask, would make this explicit.
7. Trim the public surface of Record
- Write internals are public methods:
check_field,check_sig_cohesion,wr_dats,wr_dat_files,wr_header_file,get_write_fields,get_write_subset,set_default,preprocess_headerand others. - Several fields have two names, such as
n_sigandn_signals, orfmtandformats.
The docs could list a small supported set now, with the rest given leading underscores in the next major release.
8. Say in the docs that the new API is provisional
A sentence in docs/migration.rst would let us make the changes above without surprising users, and tells them when the API will settle. For example: "The new names may change until 6.0, when they become stable and the legacy names are removed."
Suggested order
- Small changes for the next release: 3, 4 and 8.
- Need design discussion first: 1 and 2, each probably in its own issue. Settle 1 before further work on Group per-channel header fields into coherent signal metadata #744 and Decouple I/O internals from dynamic Record fields #749.
- Can follow: 5, 6 and 7.
Activity
tompollard commentedon Dec 2, 2026
Two corrections to section 3:
download_records(records="all"). Add record-specific download and listing names #794 chose it deliberately:annotators=Nonemeans no annotations, while an empty record sequence means no records. Changingrecords=Noneto mean all would make those choices less consistent.force_channelsandmissing_channelsseparate.force_channelscontrols whether a requested channel absent from selected segments of a variable-layout record remains in the result.missing_channelscontrols names absent from the record's header altogether. They answer different questions.For the proposed
write_signals, we should settle invalid-sample semantics before shipping it. Each digital storage format reserves its minimum value as a missing-sample marker. A value can fit a format's integer range while colliding with that marker, so range checking alone is insufficient.tompollard commentedon Dec 2, 2026
Proposed missing-sample contract to settle before implementing
write_signals:NaNmeans missing; reject infinity. Keep the existing format inference by default and allow an explicit format. Encoding a finite value must never produce the format's reserved missing marker.missing="none"(all values are valid) or a boolean mask. Do not infer missingness from a magic number: a format 212 read uses-2048, while format 16 uses-32768. The modern read result should carry or expose a mask established while decoding, especially when a flattened record contains segments with different formats.For the currently writable formats, the reserved marker and valid range are:
Tests should cover a digital read with missing samples written through
write_signalswith its mask, the same case across flattened segments with different formats, and rejection of a valid value that collides with an explicitly requested format's marker before files are created. Also test that physicalNaNbecomes missing and finite physical values never encode as the marker.I would settle this contract, then prototype one internal model for modern readers and writers, then implement
write_signalson that model. MutableRecordremains a compatibility view with one conversion at its write boundary and no second mutable metadata copy.Remove pn_dir from modern readers (#853)
Use signal_alignment on modern readers (#854)
Require explicit layout on read_record (#858)
Modernize iter_dataframes arguments and source paths (#859)