Skip to content

fix: matplotlib 3.10 compatibility + baseline toolkit unit tests refs #943#968

Open
ilayfalach wants to merge 4 commits into
masterfrom
issue943
Open

fix: matplotlib 3.10 compatibility + baseline toolkit unit tests refs #943#968
ilayfalach wants to merge 4 commits into
masterfrom
issue943

Conversation

@ilayfalach

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed inunits inversion bug in hera/utils/matplotlibCountour.py (inunits if inunits is not None else 1*ureg.m)
  • Added matplotlib 3.10 compatibility guard: ContourSet.collections was removed; now uses get_paths() fallback via hasattr check
  • Added 50 @pytest.mark.unit tests across two files:
    • test_matplotlibContour.py (16 tests) — toGeopandas structure, geometry, unit conversion, matplotlib version compatibility
    • test_toolkit_coverage.py (34 tests) — baseline I/O regression coverage for TopographyToolkit, LSMTemplate, OFToolkit, BriggsRural (Gaussian), and LowFreq meteorology analysis; all run without MongoDB

Test plan

  • pytest hera/tests/test_matplotlibContour.py hera/tests/test_toolkit_coverage.py -v — 50 passed
  • pytest hera/tests/ -m unit — zero MongoDB errors

Closes #943

🤖 Generated with Claude Code

Ilay Falach and others added 4 commits June 30, 2026 11:20
ContourSet.collections was removed in matplotlib 3.10 (ContourSet now inherits
from Collection directly). Replace the old collections iteration with
ContourData.get_paths() which works in both old and new matplotlib:

  - Old (<3.10): zip(ContourData.collections, levels) with inner col.get_paths()
  - New (>=3.10): zip(ContourData.get_paths(), levels) directly

Also fix a pre-existing inverted condition: `inunits if inunits is None` was
always passing None to unumToPint; corrected to `inunits if inunits is not None`.

Add 16 pytest tests in test_matplotlibContour.py covering:
  - standardize_polygon (array input, scaling, list-of-tuples)
  - toGeopandas output structure (GeoDataFrame, columns, geometry type, validity,
    level count, level values)
  - toGeopandas geometry correctness (nonzero area, unit conversion scaling)
  - matplotlib compatibility (no DeprecationWarning, new API confirmed in >=3.10,
    edge case with only 2 levels)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Mark all four test classes with @pytest.mark.unit — they use only
in-memory matplotlib/shapely objects with no external dependencies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds test_toolkit_coverage.py with 34 @pytest.mark.unit tests covering:
- TopographyToolkit.convertPointsCRS (CRS transform, roundtrip, type check)
- topographyAnalysis.calculateStastics (mean, size, max/min locations)
- LSMTemplate.prepareParams (passthrough, duration, TopoXn int-cast)
- OFToolkit.processorList + Presentation.to_paraview_CSV (glob, CSV output)
- BriggsRural.getSigma (formula accuracy, monotonicity, all stability classes)
- MeteoAnalysis.addDatesColumns (season labels, HHMM time, index fallback)

All tests run without MongoDB; optional OF dependencies mocked at sys.modules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…943

hasattr(ContourData, 'collections') returns True on matplotlib 3.8/3.9 but
accessing .collections immediately raises MatplotlibDeprecationWarning
(a DeprecationWarning subclass), causing test_no_deprecation_warning to fail
on CI (matplotlib 3.8).

Switch to explicit version comparison: use get_paths() for mpl >= 3.8
(deprecated there, removed in 3.10); fall back to .collections only for
mpl < 3.8 where it is the stable API.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Fix Matplotlib 3.10 compatibility in toGeopandas and expand toolkit unit test coverage

1 participant