Fix class_labels mutation across multi-metric write_metrics_reports#8902
Fix class_labels mutation across multi-metric write_metrics_reports#8902aymuos15 wants to merge 2 commits into
Conversation
Use a local `labels` variable per loop iteration instead of rebinding and appending to the `class_labels` parameter. Previously, after the first metric detail was written, `class_labels` was no longer None, so the else branch ran on subsequent iterations and appended an extra "mean" entry each time. This produced corrupted CSV headers (e.g. "class0,class1,mean,mean") for every metric after the first. Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Verifies that every metric detail CSV has exactly one "mean" header column, regardless of how many metrics are in the dict. Fails before the fix because `class_labels` accumulated an extra "mean" per metric beyond the first. Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRenamed the class label variable from Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
write_metrics_reportsrebinds and appends to itsclass_labelsparameter inside themetric_detailsloop. After the first metric's CSV is written,class_labelsis no longerNone. It holds["class0", ..., "classN", "mean"]. On every subsequent metric theelsebranch runs and appends another"mean", producing headers likeclass0,class1,mean,mean,mean.This hits any evaluation with two or more metrics in
metric_details, for example Dice + IoU + Hausdorff. The only real callerMetricsSaveralways passesclass_labels=None. The first metric's CSV is correct, but every one after is structurally corrupt with mismatched header and data columns.The fix uses a local
labelsvariable per iteration so the originalclass_labelsparameter is never modified. The existing test only verified existence of subsequent metric files, not their headers. A regression test is included.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.