1210: Fix plot_correlations() heatmap misalignment with non-default metrics order#1215
Draft
nikosbosse wants to merge 2 commits into
Draft
1210: Fix plot_correlations() heatmap misalignment with non-default metrics order#1215nikosbosse wants to merge 2 commits into
nikosbosse wants to merge 2 commits into
Conversation
… order (#1210) get_correlations() used a logical .SDcols, so its rows and columns came back in data-column order while the stored metrics attribute kept the user-supplied order; plot_correlations() then reordered only the columns to attribute order and labelled rows positionally, producing a doubly misaligned heatmap (diagonal not equal to 1) whenever metrics was given in a non-default order. get_correlations() now selects columns with a character .SDcols so rows, columns, the metric column and the metrics attribute share the requested order, and plot_correlations() aligns rows explicitly via the metric column, which also fixes plots of objects created by the old get_correlations(). Validation now runs before matrix construction; the error message is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1215 +/- ##
=======================================
Coverage 98.15% 98.16%
=======================================
Files 41 41
Lines 2225 2231 +6
=======================================
+ Hits 2184 2190 +6
Misses 41 41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
Automated review (Claude Fable, directed by @nikosbosse): Verdict: approve. Checks performed:
Non-blocking observations:
|
nikosbosse
marked this pull request as draft
July 18, 2026 13:53
Follow-up to the review of the plot_correlations() alignment fix: - Add a test that pins the plot-side row alignment in plot_correlations() by feeding it a row-scrambled correlations object (rows in data order, metrics attribute in a different order, as produced by the pre-fix get_correlations()). The test fails if the explicit row alignment is reverted while the get_correlations() fix stays. - Add a checkmate uniqueness assertion for the `metrics` argument in get_correlations(), so duplicated metrics error cleanly, with an accompanying expect_error test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
Follow-up (Claude Fable, directed by @nikosbosse): both non-blocking review observations are addressed in 4ad33f7.
Test file: 21 pass, 0 fail. Full suite: 0 failed, 0 errors, 917 passed. |
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.
Description
This PR closes #1210.
plot_correlations()produced a misaligned heatmap whenever the input was created withget_correlations(scores, metrics = ...)in a non-default metric order (reversed or a reordered subset): cell values were attached to the wrong metric pairs and the diagonal was not 1 (with reversed default metrics, 30 of 36 plotted cells were wrong).Cause:
get_correlations()selected score columns with a logical.SDcols, so its rows/columns came back in data-column order while the storedmetricsattribute kept the user-supplied order.plot_correlations()then reordered only the columns to attribute order and labelled the rows positionally withmetrics.Fix (as approved in #1210):
get_correlations()now selects columns with a character.SDcols = metrics, so rows, columns, themetriccolumn, and themetricsattribute all share the requested order (the originally intended behaviour).plot_correlations()now aligns rows explicitly via themetriccolumn (rownames(cor_mat) <- correlations$metric; cor_mat[metrics, , drop = FALSE]) instead of relying on positional order, so it also plots objects created by the pre-fixget_correlations()correctly. The validation check was moved before matrix construction; the error message for non-correlation input is unchanged, and the default-order vdiffr snapshot is unchanged.New tests (reversed order and reordered subset) fail on unfixed code with, e.g.:
After the fix, every plotted cell matches the true correlation matrix and the full test suite passes (0 failed, 914 passed).
Dev note: bug identified by an LLM audit (#1189); fix and tests implemented with LLM support, directed by @nikosbosse.
Checklist
lintron the changed files to check for style issues introduced by my changes.