Skip to content

Accept RecordData in write_record - #917

Merged
tompollard merged 1 commit into
mainfrom
feature/write-record-data
Dec 4, 2026
Merged

tompollard merged 1 commit into
mainfrom
feature/write-record-data

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

  • Accept RecordData in write_record(path, data) by using the same write path as data.write(path).
  • Give both forms the same signal_alignment and formats options. Keep kind and layout for mutable Record only.
  • Document the new call and add a changelog entry. The existing Record write path is unchanged.

This enables the planned 6.0 read_record/write_record pair without changing what read_record returns in 5.x.

Verification

  • 61 targeted writer tests passed.
  • Offline suite: 2,259 passed, 4 skipped, 23 deselected.
  • Ruff check and format passed; Sphinx docs built with warnings treated as errors.
  • New tests compare the function and method output byte for byte for both kinds and layouts, validated edits, conversions, skew, flattened segments, old pickles, and masked digital values with a format override. A read/write/read test checks values, masks, and logical metadata.

@tompollard
tompollard merged commit bae7952 into main Dec 4, 2026
19 checks passed
@tompollard
tompollard deleted the feature/write-record-data branch December 4, 2026 18:34
tompollard added a commit that referenced this pull request Dec 4, 2026
## Summary

- Add `RecordData.with_calibration(adc_gain=..., baseline=...,
mode=...)` for digital reads.
- `mode="reinterpret"` keeps the stored integers and changes their
physical interpretation. `mode="rescale"` adjusts the integers to
preserve physical values as closely as the new calibration permits.
- Require one gain and baseline per loaded channel. Reject missing
current calibration for rescaling, invalid gains or baselines, reserved
marker collisions, values outside known target formats, and values that
would widen the loaded integer dtype when the edit is made.
- Copy values and masks, retain source provenance, and clear
sample-dependent declarations after rescaling. Physical reads direct
callers to write options instead.

This is based on main after #917 merged. The physical write-option
change is in the stacked #919 PR.

## Rounding detail

The existing ADC implementation uses NumPy rounding, so exact halves go
to the even integer. This PR uses that same rule. The proposed “half up”
wording does not match the current code.

WFDB's existing writer requires positive gains, so this edit uses
positive finite gains rather than allowing negative ones.

## Verification

- 2,279 offline tests passed; 4 skipped and 23 network tests deselected.
- Ruff check and format passed; Sphinx docs built with warnings treated
as errors.
- New tests cover masked and expanded values, both calibration meanings,
round-trip writes, format limits, unknown source gain, input validation,
and a 5.17.0 pickle.
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.

1 participant