Repository navigation
Add immutable read_header API - #763
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 Prepare WFDB-Python 5.7.0 with the opt-in `read_header` API merged in #763 and the peak-correction fix merged in #765. This release collects both changelog fragments and bumps the version. Existing `rdheader` behavior remains available. The new reader returns an immutable description of one physical header. It supports ordinary paths, supported remote URIs, and local `.wfdb` archives, including selecting a header inside an archive. It does not load signal samples or recursively read segment headers. `processing.correct_peaks` now widens narrow and unsigned integer guesses before search-window arithmetic, avoiding overflow near signal boundaries. ## Checks - `uv build` produced the 5.7.0 source distribution and wheel. The wheel contains `wfdb.io.headers` and no `py.typed` marker. - The focused `read_header` and peak-correction tests passed (49 tests). - Sphinx HTML build passed with warnings treated as errors. - Ruff format and lint checks passed. - `git diff --check` passed. #763 and #765 passed CI before merging. The updated release PR will run CI again.
## Summary Add `Record.metadata` as an immutable snapshot of the current logical `Record` view. This is the next small step toward #743 and #371 after the source-header API in #763. The snapshot reports the record's frame and channel counts, sampling frequency, base date and time, comments, per-channel names, units, and calibration when defined. `loaded_forms` lists every signal array currently present, including both physical and digital forms after conversion. File names, formats, skew, and other source layout fields stay in the separate source-header model. Existing mutable `Record` attributes remain authoritative. Accessing `metadata` builds a new frozen object each time, so an in-place edit appears in the next snapshot without maintaining a second mutable copy. Counts come from `sig_len` and `n_sig`, so callers who manually resize an array must update those attributes too. If channel attribute lists have inconsistent lengths during an edit, `signals` is `None` while the other metadata remains available. The property is limited to `Record`; `MultiRecord` needs a separate decision about logical channel metadata and segment layout (#746). This is based on the released 5.7.0 `main` branch. It does not change the legacy read or write APIs. ## Checks - Full offline suite: 996 passed, 4 skipped, 21 network tests deselected. - Focused metadata tests: 20 passed. - Ruff format and lint passed. - Sphinx HTML build passed with warnings treated as errors.
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.