Skip to content

Ignore an invalid base time or date in a header, with a warning - #668

Merged
tompollard merged 2 commits into
mainfrom
header-invalid-base-date
Nov 23, 2026
Merged

tompollard merged 2 commits into
mainfrom
header-invalid-base-date

Conversation

@tompollard

@tompollard tompollard commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #415.

rdheader, and so rdrecord and rdsamp, could not read a record whose header has a base time or date in another form:

Record line ends with Before Now
10:30:00 25.12.2020 (or 2020-12-25, 31/02/2020) ValueError time read, date ignored with a warning
2020 (a year in place of the time) ValueError time ignored with a warning
05-Feb-2020 11:39:16 (2020 and 2021 Challenges) base time read as 00:00:05, no warning both ignored, with a warning for each

As the issue suggests, this follows the WFDB library, which ignores a date that isn't DD/MM/YYYY and reads the rest of the record. The base time and date are now read as the fifth and sixth fields of the record line, not as whatever part of the line the record line pattern matches, so a value in another form is never read in part. Valid headers are read as before: the base time and date of all 88 headers in sample-data are the same as on main.

Writing is unchanged: wrheader writes base_time and base_date from datetime objects, which are always in the WFDB form.

Testing

  • New tests for invalid dates, invalid times, the date-before-time order and a valid date (no warning). The invalid cases fail on main.
  • pytest: all offline and network tests pass. Ruff and the docs build pass.

@tompollard 🟥 red 🦥 sloth · aspen

rdheader raised a ValueError when the base date in the record line was not
a DD/MM/YYYY date (such as 25.12.2020, 2020-12-25 or a year alone), so the
whole record could not be read. Like the WFDB library, ignore such a date
with a warning, and read the rest of the header.

Fixes #415.
The record line pattern takes the parts of the line that look like a time
and a date, so "05-Feb-2020 11:39:16" was read as a base time of 5 seconds,
and a year alone in place of the time raised a ValueError. Read the base
time and date as the fifth and sixth fields instead, and ignore either one,
with a warning, if it is not valid.

@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.

Reviewed 4c54609. The parser handles invalid base time and date fields by warning and continuing, while valid header behavior remains intact. I found no actionable issues. All 110 focused offline record tests and all 18 PR checks pass. Looks good to merge from my review.

@tompollard
tompollard merged commit 78a9a58 into main Nov 23, 2026
18 checks passed
@tompollard
tompollard deleted the header-invalid-base-date branch November 23, 2026 22:51
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.

Handling WFDB header date and time problems

1 participant