Skip to content

Read format 0 signals as invalid samples #935

In review

Description

@tompollard

A record can declare a signal in format 0, meaning its samples aren't available: no signal file exists, and the file name is ~. wfdb-python reads such a header, but reading the record fails with an internal error.

format0 2 250 4
~ 0 200 12 0 0 0 0 a
~ 0 200 12 0 0 0 0 b
wfdb.read_header(path).signals[0].format             # '0'
wfdb.read_record(path, layout="uniform", kind="digital")
# KeyError: '0'   (wfdb/io/_signal.py:1534, BYTES_PER_SAMPLE[fmt])
wfdb.rdrecord(path, physical=False)                  # same KeyError

This is the format0 test record in the WFDB specification (wfdb/wfdb-spec, tests/records/format0). The specification says every sample of a format 0 signal is invalid, and WFDB C reads them that way since version 10.3.17. WFDB C 10.7.0 passes this case. WFDB Python 6.1.0 is reported as not supporting format 0 in the specification's IMPLEMENTATIONS.md.

Expected

  • read_record(..., kind="digital"): the signal is present, with every sample masked.
  • read_record(..., kind="physical"): every sample is NaN.
  • read_segments, and multi-segment reads where a segment has a format 0 signal: the same.
  • Legacy rdrecord(..., physical=True): NaN. With physical=False there is no stored missing marker for format 0, so either raise a clear error or use the smallest integer of the output type. That needs a decision, as for format 8 in Handle missing samples in format 8 reads #902.
  • Nothing is read from disk for these signals, and the record's length comes from the header.

Tests: the specification's format0 record in both kinds and layouts, and a record mixing a format 0 signal with a format 16 one in the same window.

Activity

  1. tompollard commented on Dec 6, 2026

    @tompollard
    MemberAuthor

    Decision on behaviour:

    • Modern API: read_record and read_segments with kind="digital" return format 0 signals with every sample masked. With kind="physical", every sample is NaN. Nothing is read from disk for these signals, and the record's length comes from the header. A record that mixes format 0 and other signals reads the other signals as usual.
    • Legacy rdrecord(..., physical=True): every sample is NaN, as for other missing physical samples.
    • Legacy rdrecord(..., physical=False): raise a clear ValueError, naming the format 0 signal and suggesting read_record(..., kind="digital"). A legacy digital Record has no stored missing marker for format 0, so it can't represent these samples, as for format 8 skew tails in Handle missing skew tails in format 8 reads #913.

    The fix should remove format0 from the known gaps in tests/spec_conformance.json (#939).

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