Skip to content

Prevent loading duplicate bodyparts from config#220

Merged
C-Achard merged 6 commits into
mainfrom
cy/fix-tmp-file-save-issue
Jun 9, 2026
Merged

Prevent loading duplicate bodyparts from config#220
C-Achard merged 6 commits into
mainfrom
cy/fix-tmp-file-save-issue

Conversation

@C-Achard

@C-Achard C-Achard commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Scope

  • Prevents duplicate bodyparts in all modes
  • Check for duplicates also for multianimal
  • Prevents use of "single" as individual name if uniquebodyparts are present
  • Misc:
    • Minor logging additions around h5 saves to improve traceability
    • Swapped tmp and h5 suffixes such that pandas does not attempt saving a .tmp as h5
    • Clean up tmp files when an error occurs during saving

Aims to close #219

C-Achard added 2 commits June 2, 2026 10:13
Enhance write_hdf and write_hdf_napari_dlc with additional debug logs and stronger error handling. write_hdf now logs HDF/CSV paths, records and logs the written paths and their existence, and wraps the final disk writes in a try/except to log exceptions before re-raising. write_hdf_napari_dlc logs entry/return values and existence of produced files and keeps the dummy-path behavior for napari-specific handling. Minor whitespace/logging tweaks in _writer.py and core/io.py.
Use a hidden per-directory temp file (.{stem}.tmp{suffix}) instead of altering the suffix, and wrap the write+replace in try/except. On failure the code logs the exception, attempts to remove the temp file (logging at debug level if that removal fails), and re-raises the error. This makes atomic HDF writes more robust and ensures temporary files are cleaned up and failures are recorded.
@C-Achard C-Achard self-assigned this Jun 2, 2026
@C-Achard C-Achard added bug fix Fixes an issue or a bug I/O Related to reading/writing in the plugin: h5, csv, videos, etc labels Jun 2, 2026
C-Achard added 2 commits June 2, 2026 11:32
In write_hdf (src/napari_deeplabcut/core/io.py) add diagnostic logging: emit a debug line with total and unique column counts and, if there are duplicate columns, log an error with a sample (up to 50) of duplicate column names. This helps identify column-duplication issues prior to writing the .h5/.csv outputs for easier debugging.
Introduce a _find_duplicates helper and use it in DLCHeaderModel.from_config to detect duplicate entries in "individuals", "multianimalbodyparts", "uniquebodyparts", and single-animal "bodyparts". Raise clear ValueError messages listing duplicates and reject configs where an individual named "single" conflicts with uniquebodyparts. These checks prevent ambiguous/invalid config.yaml headers.
@C-Achard C-Achard changed the title Improve logging around h5 saving Prevent duplicate bodyparts from config Jun 5, 2026
@C-Achard C-Achard requested a review from deruyter92 June 5, 2026 15:26
@C-Achard C-Achard marked this pull request as ready for review June 5, 2026 15:26

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me! Just minor comments

Comment thread src/napari_deeplabcut/config/models.py Outdated
Comment thread src/napari_deeplabcut/core/io.py
C-Achard and others added 2 commits June 9, 2026 08:24
Co-authored-by: Jaap de Ruyter van Steveninck <32810691+deruyter92@users.noreply.github.com>
@C-Achard C-Achard changed the title Prevent duplicate bodyparts from config Prevent loading duplicate bodyparts from config Jun 9, 2026
@C-Achard C-Achard merged commit 786a628 into main Jun 9, 2026
12 checks passed
@C-Achard C-Achard mentioned this pull request Jun 9, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Fixes an issue or a bug I/O Related to reading/writing in the plugin: h5, csv, videos, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

napari plugin fails to save labels

2 participants