Skip to content

Make header text round-trip consistently across sources #915

Done

Description

@tompollard

Problem

WFDB-Python can write header text that it cannot read back unchanged. The writer uses UTF-8 (io/util.py and archive writes in _header.py), but local header reads use ASCII with errors="ignore" (record.py), which silently drops non-ASCII characters. PhysioNet header reads decode as ISO-8859-1 (download.py), so the same UTF-8 bytes are interpreted differently by source. Cloud and archive paths need to be covered by the same decision.

Comments have a separate loss: _parse_header_fields uses line.strip(" \t#"), removing leading and trailing spaces and # characters. For example, a written comment # #hash reads back as hash.

This predates #914. That PR restricts its new metadata edit methods to text that survives the current reader, but it does not settle the package-wide header policy. Legacy writers can still write text that is silently changed on read.

Decision and tests

  • Choose and document a consistent encoding for local, cloud, archive, and PhysioNet headers. If existing Latin-1 headers need support, define an explicit fallback rather than silently dropping bytes.
  • Decide whether comments should preserve edge spaces and #, or whether writers should reject them before writing.
  • Add read/write round-trip tests for Unicode names, units, and comments, plus existing Latin-1 headers and comment edge cases, across the supported source types.
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