Fix visualization reshape error with descriptive error messages and validation#3047
Merged
MMathisLab merged 2 commits intomwm/humanbodyfrom Jul 5, 2025
Merged
Conversation
…hensive tests Co-authored-by: MMathisLab <28102185+MMathisLab@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix visualization error in plot_evaluation_results function
Fix visualization reshape error with descriptive error messages and validation
Jul 5, 2025
MMathisLab
approved these changes
Jul 5, 2025
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.
Problem
The
plot_evaluation_resultsfunction indeeplabcut/utils/visualization.pywas failing with cryptic reshape errors when the input data didn't match expected dimensions:This error provided no context about what data was being processed or why the reshape failed, making it difficult for users to debug data structure issues.
Root Cause
The function performed direct
.reshape()operations without validating that the array size matched the target dimensions:When the actual data didn't contain the expected number of individuals, bodyparts, or coordinates, these reshapes would fail with uninformative error messages.
Solution
Added a
safe_reshapefunction that:Example Error Message Improvement
Before:
After:
Changes Made
safe_reshapefunction with comprehensive validation and error reportingplot_evaluation_resultsto usesafe_reshapewith meaningful contextValidation
This fix transforms frustrating debugging sessions into clear guidance for users when their data doesn't match expected structure, while ensuring robust validation prevents silent failures.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.