Skip to content

Define behavior when a Record holds multiple signal representations #768

Done

Description

@tompollard

Problem

A Record can legitimately hold both physical and digital signal arrays. For example, after a physical read, record.d_signal = record.adc() or record.set_d_features(do_adc=True) adds d_signal while leaving p_signal in place. The reverse is possible with dac() and set_p_features(do_dac=True).

The arrays are independent and can drift apart after an edit. Different operations then choose different values: Record.to_dataframe() prefers p_signal, while Record.wrsamp() writes an existing d_signal. A caller could therefore inspect one version and write another without an explicit choice.

record = wfdb.rdrecord("100", pn_dir="mitdb", sampto=10)
record.d_signal = record.adc()
record.p_signal[0, 0] = 0  # d_signal still contains the previous value
# to_dataframe() reads p_signal; wrsamp() uses d_signal.

Decision needed

Define what it means for a record to hold multiple signal representations, including precedence and stale values after edits. Options include documenting an explicit active representation, clearing or invalidating other representations on conversion/edit, or making a future signal-value API hold one canonical representation and return conversions separately. Any change to existing Record methods should account for compatibility.

Related: #745 (loaded signal representation and conversion design), #743 (metadata versus values), and #767 (Record.metadata reports all forms present without choosing a primary one).

Activity

  1. viranovskaya commented on Nov 29, 2026

    @viranovskaya

    I’d keep the current behavior for Record and document which array each method uses. Making physical values always win on write would just reverse the problem for someone who edited d_signal. An “active” flag set on assignment would also miss edits through a NumPy slice.

    With sample-data/100, editing the first physical sample to 0 mV gives 0 in the DataFrame, but the written file still contains 995 counts (−0.145 mV). Calling record.set_d_features(do_adc=True) before record.wrsamp() makes the file read back as 1024 counts (0 mV), as intended. The same works for expanded signals with expanded=True on both calls.

    Would a small PR documenting this and adding a write/read-back test for each layout be useful? I’d leave the canonical representation decision for the new API in #745.

  2. tompollard commented on Nov 29, 2026

    @tompollard
    MemberAuthor

    Thanks, I agree. #767 makes Record.metadata report all arrays that are present without choosing an active one. For the existing Record API, documenting which array each method uses seems like the right next step. A small PR with documentation and write/read-back tests for both uniform and expanded signals would be welcome. We can decide on a canonical representation for the new API in #745.

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