Skip to content

fix(thermo): guard empty legend under matplotlib 3.11+ - #232

Draft
jmmshn wants to merge 1 commit into
mainfrom
jmmshn/pmg-defects-epic-7
Draft

fix(thermo): guard empty legend under matplotlib 3.11+#232
jmmshn wants to merge 1 commit into
mainfrom
jmmshn/pmg-defects-epic-7

Conversation

@jmmshn

@jmmshn jmmshn commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Fixes the tests/test_thermo.py::test_plotter failure that has been red on main since 2026-06-12.

Root cause

matplotlib 3.11.x tightened _parse_legend_args. On the failing branch of test_plotter, both artists + handle and legends_txt + leg are empty; the prior axis.legend(handles=[], labels=[], ...) call previously warned but is now a ValueError.

Fix

Skip axis.legend(...) entirely when the combined handles/labels are empty. No behavior change for callers that actually pass artists — the old empty-legend was already a no-op modulo the warning.

Verification

pytest tests/test_thermo.py::test_plotter -x  # was ValueError, now passes
pytest tests/test_thermo.py -x                # full file green

Reproduced pre-fix locally on matplotlib==3.11.1.

Bead: pmg-defects-epic.7

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.78%. Comparing base (12c1f80) to head (a9a6141).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pymatgen/analysis/defects/thermo.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
- Coverage   90.94%   90.78%   -0.17%     
==========================================
  Files          14       14              
  Lines        2265     2268       +3     
  Branches      287      288       +1     
==========================================
- Hits         2060     2059       -1     
- Misses        118      120       +2     
- Partials       87       89       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant