Repository navigation
Warn when a renamed record would replace another record's signal files - #675
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Reviewed commit 618775f. I found two issues:
-
The warning misses a rename that overwrites another record (
src/wfdb/io/record.py, lines 1003-1010). Thefile_name.startswith(record_name)check treats100_extra.datas belonging to record100. I wrote a100_extrarecord, changed only itsrecord_nameto100, and wrote it again:100_extra.datwas overwritten without a warning. This is the data-loss case the PR aims to expose. Please cover this prefix case. -
Existing tests fail when warnings are errors. The 116 offline record tests pass normally but emit two new
UserWarnings. A focused run with-W error::UserWarningfails intest_4a, contrary to the PR testing claim. If these overwrites are intentional in the tests, please make the tests expect the warnings.
All CI checks pass. I would address these before merging.
|
Thanks, both fixed in 70aa455.
|
Record.wrsamp names the header after record_name but the signal files by file_name, so a record read and given a new record_name, then written next to the original, silently replaced the original's signal files. Warn when writing would replace an existing signal file whose name does not start with record_name, and explain this, with an example, in the documentation of wrsamp and file_name, which said only "the name of the file used for analysis". Fixes #153.
The warning treated any signal file whose name started with the record name as the record's own, so renaming record 100_extra to 100 replaced 100_extra.dat without a warning. A file is now the record's own only if the record's existing header in write_dir lists it, as when a record is written again. Two tests in TestRecord wrote records whose signal file is shared with another sample record (test01_00s.dat) into the directory shared by the class, so they replaced a file written by another test and triggered the warning. Give them their own directories.
70aa455 to
a989032
Compare
## Summary Bump the version from 5.1.0 to 5.2.0, and collect the 19 entries in `changelog.d/` into `docs/changes.rst` with `towncrier build --date "Nov 2026"`, with a short summary at the top of the new section. This is a minor release. The one change that existing code may notice is that `rdann` and `Annotation.apply_range` now stop before `sampto`, as `rdrecord` and `rdsamp` do, so an annotation exactly at `sampto` is no longer included (#667). The summary calls it out, with how to get the old result. The release also includes: - **Fixes for PhysioNet:** `get_dbs`, which PhysioNet's API change had broken (#665), record names with folders in `pn_dir` (#666), and `physionet://` and other URIs in `read_edf`, `rdedfann` and `read_wav` (#674). - **Robustness:** - headers whose base time or date is in another form (#668); - multi-segment writes that leave no partial record after an error (#673); - a warning before `wrsamp` replaces another record's signal files (#675). - **New:** a beat-by-beat comparison of annotation files, as WFDB `bxb` does, as a development feature (#679), and axis labels in `plot_wfdb` (#670). - **Smaller fixes:** - integer overflow and precision in `find_peaks` and `normalize_bound`; - constant signals in `normalize_bound`; - multi-character custom annotation symbols; - format 61 signals read with `smooth_frames=False`; - skew written twice when rewriting records; - docstring examples, and more. This will be the first release published by `.github/workflows/publish.yml`, from the GitHub release, with provenance. ## Checks - `pytest -m "not network"`: 679 passed (4 skipped, the `bxb` comparison that needs WFDB installed), also with `--python 3.11 --resolution lowest-direct`. `pytest -m network`: 20 passed. - Ruff and the Sphinx HTML build with warnings as errors pass. - The wheel and source distribution build and pass `twine check`. They have `Version: 5.2.0` and include `wfdb/processing/beat_comparison.py`. - PyPI has no 5.2.0 release yet. <sub>@tompollard 🟥 red 🦥 sloth · aspen</sub>
Fixes #153.
Record.wrsampnames the header afterrecord_name, but the signal files byfile_name. So the example in the issue, reading record 100, settingrecord_name = "100_cloned"and writing it, gives100_cloned.heaand100.dat. Next to the original record, that silently replaces the original's100.dat. This is by design, since a record's signals may be split across several files or shared with other records. This PR makes it visible rather than changing it.A warning in the risky case:
wrsampwarns, before writing anything, when it would replace an existing signal file that the record's own header inwrite_dirdoesn't list. The warning names the files, and points at the user's ownwrsamp()call:It isn't given in these cases:
.wfdbarchive;rec_0001e.datfor recordrec_0001, as in MIMIC-IV-WDB.It is given for a file named like the record but belonging to another one, such as
100_extra.datwhen record100_extrais renamed to100.It's a warning, not an error, so code that does this on purpose keeps working.
Documentation: the
wrsampdocstring explains how files are named, with an example of saving a copy under a new name. Thefile_namedescription said only "The name of the file used for analysis", and now explains the same.Naming new files after the record by default could be part of the API redesign in #672 (for example a
copy(record_name=...)method), rather than a change towrsamp.Testing
main.pytest -m "not network", run serially with this warning turned into an error, passes. Two existing tests wrote a record that shares its signal file with another sample record into the directory their class shares, so they replaced another test's file; they now use their own directories. Network tests, ruff and the docs build pass.@tompollard 🟥 red 🦥 sloth · aspen