Repository navigation
Read units containing any non-whitespace characters - #609
Merged
Merged
Conversation
tompollard
reviewed
Oct 31, 2026
tompollard
left a comment
Member
There was a problem hiding this comment.
Thanks, this looks good! \S* matches what the WFDB C library does: readheader in lib/signal.c takes everything after the first / in the gain field, up to the next whitespace, as the units.
I also read all 88 headers in sample-data with rdheader on main and on this branch, and every field is identical.
TheNetherWatcher
force-pushed
the
header-units-regex
branch
2 times, most recently
from
October 31, 2026 18:41
ac1fde9 to
de5e47e
Compare
The units in a signal line were matched with a character class that left out characters such as '.' and '*', so units like 'a.u.' were cut off and the rest of the line was read as the signal name. WFDB only excludes whitespace from units, which is also what wrsamp checks, so match any non-whitespace characters.
TheNetherWatcher
force-pushed
the
header-units-regex
branch
from
October 31, 2026 18:49
de5e47e to
5373b0a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The units in a signal line are matched with
[\w\^\-\?%\/]*, which leaves out characters such as.and*. Units likea.u.are cut off at the first such character, and the rest of the line ends up in the signal name:WFDB only excludes whitespace from units, and
wrsampalready allows any units without whitespace, so the regex now matches\S*.I parsed every signal line in
sample-data/with the old and new regex. The only differences are intest_generator_2.hea, where two signals have units°and the old regex put the whole rest of the line into the signal name. (rdheadercurrently drops non-ASCII characters before parsing, so this doesn't show up when reading that record.)Tests:
wrsampthenrdheaderround trip formV,a.u.,uV*s,mmHg/sand10^-3, checking units, signal name and ADC resolution. Thea.u.anduV*scases fail onmain.pytest -m "not network"passes (101 tests), and the docs build passes.