Prevent loading duplicate bodyparts from config#220
Merged
Conversation
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.
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.
deruyter92
approved these changes
Jun 9, 2026
deruyter92
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me! Just minor comments
2 tasks
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
Aims to close #219