Skip to content

Read format 0 signals as missing - #943

Open
tompollard wants to merge 1 commit into
mainfrom
fix-format0
Open

tompollard wants to merge 1 commit into
mainfrom
fix-format0

Conversation

@tompollard

@tompollard tompollard commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #935. This is the first open PR in the Python stack: #943 → #944 → #945. The matching spec adapter is wfdb-spec #34. After that adapter merges, I will pin a commit reachable from spec main.

Behavior differences from 6.1.0

  • Modern read_record and read_segments return a fully masked digital format 0 channel or an all-NaN physical channel, in either layout. Previously they raised an internal KeyError.
  • Legacy rdrecord(..., physical=True) returns NaN for format 0; rdrecord(..., physical=False) raises a ValueError naming the channel and pointing to read_record(..., kind="digital") instead of an internal KeyError.
  • A format 0 channel does not open a signal file. Other channels in a mixed record retain their values.

The format0 known gap is removed. Tests cover both kinds, both layouts, mixed records and segmented reads.

Verification on the stacked tip: pinned WFDB spec suite (35 passed), parallel offline suite (2,484 passed, 4 skipped), Ruff, and the warnings-as-errors Sphinx docs build.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour is right. One change is needed before merging: the specification pin.

Behaviour, as agreed on #935

  • read_record(..., kind="digital") on the specification's format0 record gives every sample masked. kind="physical" gives every sample NaN.
  • Legacy rdrecord gives NaN for physical values. For digital values it raises "Signal 'a' (channel 0) has format 0 and cannot be represented in a digital legacy Record; use read_record(…)".
  • A record mixing two format 212 signals with a format 0 one reads the 212 signals normally, and the format 0 column is masked.
  • Against main (0c1a867), my 3,520 single-segment and 976 multi-segment comparisons show no differences. No sample record uses format 0.

To change: the specification pin

tests/spec_conformance.json now pins ad32e32, the head of the unmerged wfdb/wfdb-spec#34. Two problems:

  1. CI clones the specification and checks out that SHA. If #34 is squash-merged and its branch deleted, the commit is no longer on any branch, and this job fails on main.
  2. #944 and #945 pin different unmerged commits (6bcb9cc and 697cd4f), so whichever merges second conflicts on this file.

Please merge the adapter change in wfdb-spec first, then pin the resulting commit on wfdb-spec main. See my comment on #945 for the order across the three PRs.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks. I agree that the pin should point to a commit reachable from the spec's main, rather than an unmerged PR head.

#940–#942 merged while I was assembling the stack, so #943 is now rebased on current main; #944 is based on #943, and #945 on #944. The spec adapter PRs are stacked as wfdb/wfdb-spec#34 → #35 → #36. Once #34 and #35 merge, I can update the pins in #943 and #944 to a reachable spec main commit.

I checked the suggestion to merge all three adapters first. Running #943 against #36's adapter makes the existing multi-segment-variable case error, because its direct digital reader needs #933's fix. So #36 needs to stay after #945's reader change. I'll keep #943 open until its pin is updated.

This branch has not been deployed

No deployments
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.

Read format 0 signals as invalid samples

1 participant