Repository navigation
Add immutable read_header API - #763
tompollard wants to merge 5 commits into
Conversation
|
Thanks for putting this together, Tom. I tried One small question, with no change implied: on a minimal header ( Thanks again, and no rush. Heywood Geblomi |
## Summary Prepare a 5.6.0 minor release from current `main` as a checkpoint for the merged record I/O refactoring. The release keeps the existing public API and leaves the proposed `read_header()` API in #763 for a later release. This bumps the version and collects the pending changelog fragments for the record comparison and `csv2ann` fixes, the calibration documentation, and the internal reader changes. ## Checks - `uv build` - Ruff format and lint checks - Sphinx HTML build with warnings treated as errors - `git diff --check` The built wheel reports version 5.6.0 and does not contain the new `read_header()` module from #763.
tompollard
left a comment
There was a problem hiding this comment.
I don't see a runtime regression, but I would resolve two parts of the public API before release:
-
read_headeris described as typed, but its public signature has no parameter or return annotations (src/wfdb/io/record.py:2292), and the package has nopy.typedmarker. Installed-package type checkers therefore cannot expose the return type to callers. If static typing is intended, please annotate the signature and decide how to publish the type information. Otherwise, describe this as an immutable, structured header rather than a typed API. -
SegmentHeader(src/wfdb/io/headers.py:34-39) contains only a segment name and length. It does not contain the referenced segment's header. I would call thisSegmentReferenceorSegmentEntrybefore the name becomes public; changing it later would break callers.
I would also confirm the intended multi-segment contract. For 041s, read_header() reports seven signals but exposes none of their names or units; rdheader(..., rd_segments=True) can retrieve them. Reading exactly one physical header per call is a coherent design, but the documentation should make clear how callers obtain segment signal metadata. In particular, a typed layout-only read would address the use case in #442. If read_header is intended to replace rdheader, I would decide on that access pattern before promoting it.
The full offline suite passed (934 passed, 4 skipped, 21 deselected). I also compared the shared fields against rdheader() across all 88 sample headers and found no differences.
|
@HeywoodGeblomi Yes, that is intentional. I clarified this distinction in the |
997cf00 to
ea0b256
Compare
|
I addressed the public API review and rebased the PR onto 5.6.0.
The focused tests, Ruff, docs build, and package build passed after the latest change. |
tompollard
left a comment
There was a problem hiding this comment.
The update addresses my previous points: the public function has type annotations, the wheel includes py.typed, SegmentReference names the entry accurately, and the one-header-per-call behavior is documented.
One case remains for multi-segment .wfdb archives. read_header(archive_path) reads only the main header (src/wfdb/io/record.py:2404-2412), and the public API has no way to select a segment header inside that archive. I reproduced this with an archive containing 041s.hea, 041s01.hea, and 041s02.hea: rdheader(archive_path, rd_segments=True) retrieves the first segment's signal names, but passing archive_path/041s01 to read_header raises NotADirectoryError. The documentation's advice to pass a segment path to read_header does not work for this supported archive form.
I would decide before release whether to add a way to name an archive member, such as an optional segment argument, or explicitly document that typed segment reads from archives are unavailable. An archive member option would preserve the one-physical-header-per-call contract.
The full offline suite passed (935 passed, 4 skipped, 21 deselected).
|
Good catch. I added a main = wfdb.read_header("041s.wfdb")
first = wfdb.read_header("041s.wfdb", segment=main.segments[0].name)This still returns one physical header per call. The argument also works for a variable-layout record's zero-frame layout segment. I updated the docs and added tests for fixed-layout and variable-layout archives, missing members, and invalid argument combinations. The offline suite passed (937 passed, 4 skipped, 21 network tests deselected), as did Ruff and the warnings-as-errors docs build. |
|
Follow-up to my archive reply: I considered making |
576b344 to
380f157
Compare
|
I removed The rebuilt wheel has no |
Summary
Add
wfdb.read_header(path)as a metadata-only API. It returns an immutableSingleSegmentHeaderwith per-signal entries or aMultiSegmentHeaderwith segment references. The new objects use clearer names such asn_signals,n_frames,samples_per_frame, andformat, while keeping WFDB terms such asfs,adc_gain,baseline, andskew.The result describes one physical header. It applies some WFDB header defaults but leaves omitted optional fields such as
adc_zeroasNone, and keepsn_framesasNonewhen length is omitted. It reads no signal samples or referenced segment headers. For a local.wfdbarchive,segment=selects one header inside the archive.rdheader()continues to return mutableRecord/MultiRecordobjects, including itsrd_segments=Truebehavior. This makesread_header()a deliberate new API rather than a direct alias, as discussed in #743 and #672. I have not added a warning tordheader()because its recursive behavior does not yet have an equivalent in the new API.The new API retains inline annotations. This PR does not ship
py.typed: package-wide typing needs further work on the existing public APIs before we ask type checkers to rely on them.Checks
read_headertests passed.uv buildpassed; the wheel contains the new API and nopy.typedmarker.