Skip to content

Document source location contract for record I/O - #780

Merged
tompollard merged 2 commits into
mainfrom
source-location-contract
Nov 30, 2026
Merged

tompollard merged 2 commits into
mainfrom
source-location-contract

Conversation

@tompollard

@tompollard tompollard commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Document one source-location contract for WFDB record and annotation reads before introducing more public API names:

  • The first argument holds a local record stem, supported cloud URI, explicit physionet:// URI, or local .wfdb archive path. EDF and WAV converters take a file path with its extension.
  • Reads do not fall back from local files to PhysioNet. Combining a URI with pn_dir now raises a clear ValueError across record, annotation, EDF, and WAV readers.
  • Keep pn_dir supported for custom index servers configured with set_db_index_url; an explicit physionet:// URI always targets PhysioNet. A versionless pn_dir still asks PhysioNet for the latest version, so custom servers should be used with an explicit version. Do not deprecate pn_dir until a replacement for custom servers exists.
  • State the current write contract separately: legacy writers use write_dir; only wrsamp accepts wfdb_archive, while SignalRead.write(path) takes a full destination stem or archive path.

The concise overview links to the existing archive, cloud, and PhysioNet sections. New readers use path; existing record_name arguments remain unchanged. The README quick start and iter_dataframes example now use explicit PhysioNet URIs.

Closes #748. Related: #534 and #672.

Verification

The offline suite passes (1,066 passed, 4 skipped, 22 network tests deselected). Ruff check and format pass. Sphinx HTML documentation builds with warnings treated as errors.

@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 decisions here are right: no implicit fallback to PhysioNet, and keeping pn_dir until custom servers have another option. I checked each claim against the code, including live PhysioNet reads. Most hold, but three sentences don't match what the code does.

Verified:

  • physionet://mitdb/1.0.0/100 and physionet://mitdb/latest/100 both work with rdrecord, rdann, read_header, read_signal_values, read_multi_segment_headers and ann2rr.
  • There's no fallback: rdrecord("100") in an empty folder raises FileNotFoundError.
  • A physionet:// URI ignores set_db_index_url. With the index set to a custom server, the URI still read from PhysioNet, and pn_dir read from the custom server.
  • Cloud archives raise "Reading .wfdb archives from cloud storage is not supported".
  • read_edf, rdedfann and read_wav read memory:// and physionet:// paths that include the extension.

Mismatches

  1. Combining a URI with pn_dir behaves inconsistently. The section says the two "should not be combined", but what actually happens depends on the reader:

    • rdrecord, rdann and read_signal_values fail with a doubled path, for example FileNotFoundError: physionet://mitdb/1.0.0/physionet://mitdb/1.0.0/100.hea.
    • read_header(URI, pn_dir="nonexistentdb") succeeds and ignores pn_dir, because the cloud check in _read_header_fields runs before the pn_dir branch.

    This also contradicts "the name is the only difference in how these readers locate files". There's a precedent for handling it: _check_archive_read_args raises ValueError("pn_dir cannot be used to read a .wfdb archive"). A matching ValueError for a URI plus pn_dir would make the contract true. It could be added here or in a follow-up. Either way, the docs could describe combining the two as an error.

  2. The version lookup always asks PhysioNet. "Without a version in pn_dir, WFDB-Python looks up the database's latest version" holds for PhysioNet. With a custom index set, though, the lookup still asks PhysioNet: pn_dir="mitdb" against a custom server requested /files/mitdb/1.0.0/100.hea. A mirror that lacks PhysioNet's latest version would then fail. Since custom servers are the reason given for keeping pn_dir, it would help to say that pn_dir should include the version when using one.

  3. wrann can't write archives. The write paragraph names wrsamp and wrann, then says to pass wfdb_archive. Neither Annotation.wrann nor wfdb.wrann takes that argument, so the paragraph should say that only wrsamp writes archives.

Fit with the rest of the docs

  • "Reading From PhysioNet" already covers latest, how pn_dir maps to URIs, the version lookup and set_db_index_url. "Cloud Storage Access" and "WFDB Archives" overlap with the new section too. Keeping the new section as a short summary that links to those would leave one place for each rule. Otherwise, item 2 has to be fixed in two places.
  • The section recommends URIs for new code reading from PhysioNet. However, the iter_dataframes example (io.rst:320) and the README quick-start (README.md:34-35) still use pn_dir. Updating those two would make the examples match the advice.

@tompollard
tompollard force-pushed the source-location-contract branch from 44e9e2a to fc58e70 Compare November 30, 2026 05:14
@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the contract against the code. I fixed all three mismatches:

  • Passing a URI together with pn_dir now raises the same clear ValueError across record and annotation readers, including read_header, and the EDF/WAV readers. I added regression cases for each entry point.
  • The docs now say that a versionless pn_dir still looks up the latest version on PhysioNet, even when a custom index server is configured. They recommend an explicit version for custom servers.
  • The write section now says that only wrsamp accepts wfdb_archive; wrann does not.

I shortened the source-location overview and linked it to the existing archive, cloud, and PhysioNet sections. The README quick start and iter_dataframes example now use explicit PhysioNet URIs. I also rebased #780 onto main after the 5.9.0 release.

The full offline suite passes (1,066 passed, 4 skipped), as do Ruff and the strict Sphinx build.

@tompollard
tompollard merged commit e475859 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the source-location-contract branch November 30, 2026 05:21
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.

Specify one source-location contract across record I/O

1 participant