Skip to content

Accept pathlib.Path record names in rdann - #626

Merged
tompollard merged 1 commit into
mainfrom
tp/rdann-pathlike
Nov 4, 2026
Merged

tompollard merged 1 commit into
mainfrom
tp/rdann-pathlike

Conversation

@tompollard

Copy link
Copy Markdown
Member

rdann fails when record_name is a pathlib.Path:

wfdb.rdann(pathlib.Path("sample-data/100"), "atr")
# TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'

The file name is built with record_name + "." + extension. rdrecord, rdsamp and rdheader already accept path-like objects, so rdann now converts record_name with os.fspath at the start, and the docstring says str or os.PathLike.

This is the remaining part of #346, without the changes to how PhysioNet URLs are built.

Tests: reading sample-data/100 with a Path gives the same annotations as with a string (this fails on main), and reading from a .wfdb archive given as a Path works too.

rdann built the annotation file name with record_name + "." + extension,
which fails for a pathlib.Path. Convert record_name with os.fspath at the
start, as rdrecord, rdsamp and rdheader already accept path-like objects.

@lukepayyapilli lukepayyapilli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Tom, checked 4370a52b locally merged with main:

  • Fix: converting with os.fspath at the top means every later use gets a str, including the rdheader fallback for fs. rdann(pathlib.Path("100"), "atr", pn_dir="mitdb") also works against PhysioNet. ann2rr and the processing functions that call rdann accept a Path now as well.
  • Tests: test_rdann_path fails on main with the TypeError and passes here. test_rdann_archive_path already passes on main, since the archive code converts the path itself, so it guards the archive case rather than this fix. The full suite gives 337 passed, 2 skipped (PhysioNet timeouts).
  • Style and docs: ruff format --check and ruff check are clean, the docs build passes with -W, and the changelog entry renders correctly in towncrier build --draft.

@tompollard
tompollard merged commit f298146 into main Nov 4, 2026
18 checks passed
@tompollard
tompollard deleted the tp/rdann-pathlike branch November 4, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Assignees

Couldn't load assignees.