Skip to content

contour: test coverage for all-equal auto-levels and empty explicit levels#3353

Merged
brendancol merged 3 commits into
xarray-contrib:mainfrom
Melissari1997:issue-3352
Jun 15, 2026
Merged

contour: test coverage for all-equal auto-levels and empty explicit levels#3353
brendancol merged 3 commits into
xarray-contrib:mainfrom
Melissari1997:issue-3352

Conversation

@Melissari1997

@Melissari1997 Melissari1997 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #3352

Summary

  • Add test_contours_flat_auto_levels — asserts an all-equal raster with levels=None returns [] (covers the vmin == vmax branch in auto-level generation)
  • Add test_contours_empty_explicit_levels_numpy — asserts levels=[] with numpy return type returns []
  • Add test_contours_empty_explicit_levels_geopandas — asserts levels=[] with geopandas return type returns an empty GeoDataFrame

Backend coverage

Numpy only (both edge cases hit the early-return path before backend dispatch).

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Jun 15, 2026

@Melissari1997 Melissari1997 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Test coverage for all-equal auto-levels and empty explicit levels

Changed file: xrspatial/tests/test_contour.py

Blockers (must fix before merge)

None. All tests are logically correct and target real coverage gaps not exercised by existing tests.

Suggestions (should fix, not blocking)

S1 — Use create_test_raster instead of raw xr.DataArray

All three new tests construct the raster with raw xr.DataArray(...) rather than the project's create_test_raster helper. Every other test in this file that exercises contour behavior uses create_test_raster, which sets up dims, coords, units, and CRS attrs consistently. Using the raw constructor means:

  • No coords are set
  • The CRS attribute is absent

At minimum the geopandas test should test with a CRS-bearing raster to exercise the CRS-propagation path (consistent with other empty-result geopandas tests at test_geopandas_empty_result_keeps_crs and test_geopandas_all_nan_keeps_crs).

xrspatial/tests/test_contour.py:1515, 1527, 1537

S2 — Class naming doesn't follow project convention

The class is named TestIssue3352Coverage. The existing convention is descriptive class names like TestEdgeCases, TestNaNBackendParity, TestGeoDataFrame, etc. A descriptive name would be more maintainable.

xrspatial/tests/test_contour.py:1507

S3 — test_contours_empty_explicit_levels_geopandas misses column assertions

The existing test test_geopandas_empty_result_keeps_crs asserts 'level' in gdf.columns and 'geometry' in gdf.columns on an empty GeoDataFrame. The new geopandas test checks isinstance and len == 0 but does not verify the expected schema.

xrspatial/tests/test_contour.py:1540-1542

Nits (optional improvements)

N1 — Double-quote style for dims strings

The rest of the file consistently uses single quotes for string literals (dims=['y', 'x']). All three new tests use double quotes (dims=["y", "x"]).

xrspatial/tests/test_contour.py:1515-1516, 1528, 1538

N2 — assert result == [] vs explicit type + length checks

assert result == [] works for the numpy return case. However, other tests in this file (e.g. test_no_contours_flat) use assert isinstance(result, list) separately. An object of the wrong type (e.g. a tuple ()) would slip past == [].

xrspatial/tests/test_contour.py:1519, 1531

What looks good

  1. Tests target genuine coverage gaps — test_no_contours_flat tests flat rasters with explicit levels, so the levels=None auto-level path was not exercised with vmin == vmax.
  2. Both return types (numpy and geopandas) are covered for the empty-levels case.
  3. pytest.importorskip("geopandas") is used for the geopandas test, consistent with the rest of the file.
  4. Docstrings are clear and explain why these cases matter.
  5. Minimal and focused — each test does exactly one thing.

Checklist

  • Covers stated gap: all-equal auto-levels, empty explicit levels
  • Correct assertions
  • Follows file conventions (see S1, S2, N1)
  • pytest.importorskip used appropriately

@Melissari1997 Melissari1997 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (after fix commits)

Disposition of previous findings

Finding Status Notes
S1 — use create_test_raster Fixed All three tests now use create_test_raster
S2 — class naming convention Fixed Renamed to TestFlatAutoLevelsAndEmptyLevels
S3 — geopandas column assertions Fixed level and geometry columns now asserted
N1 — double-quote style Fixed Switched to single quotes throughout
N2 — bare == [] assert style Fixed Both numpy tests now use isinstance + len

No new issues found. All previous findings are resolved.

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Melissari1997 LGTM...thanks again

@brendancol brendancol merged commit c9c9485 into xarray-contrib:main Jun 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contour: test gaps for all-equal auto-levels and empty explicit levels

2 participants