Reason or Problem
Two edge cases in contours() are not tested:
-
All-equal raster with auto-levels. test_no_contours_flat passes explicit levels=[], so it never exercises the auto-level branch (levels=None) on a flat raster where vmin == vmax. That branch calls np.linspace(vmin, vmax, n_levels + 2)[1:-1] which produces identical levels on equal min/max — the function returns an empty result, but no test asserts this.
-
Empty levels=[]. Passing an empty list as levels returns [] silently. No test documents that this is the intended behavior or that it does not raise.
Proposal
Design: Add two test functions to xrspatial/tests/test_contour.py:
def test_contours_flat_auto_levels():
raster = xr.DataArray(
np.ones((10, 10), dtype=np.float64), dims=["y", "x"]
)
result = contours(raster, levels=None, n_levels=10)
assert result == []
def test_contours_empty_explicit_levels():
raster = xr.DataArray(
np.random.rand(10, 10), dims=["y", "x"]
)
result = contours(raster, levels=[], return_type="numpy")
assert result == []
result_gdf = contours(raster, levels=[], return_type="geopandas")
assert len(result_gdf) == 0
Value: Covers two branches with zero test coverage, preventing regressions on the auto-level range computation and the empty-levels path that the geopandas empty-GeoDataFrame CRS fix (#2700) depends on.
Stakeholders and Impacts
Test-only change. No source modification needed.
Drawbacks
Negligible — two small deterministic tests.
Alternatives
- Rely on the accuracy and performance sweeps catching regressions here.
- File separate issues per gap (combined here for minimal overhead).
Reason or Problem
Two edge cases in
contours()are not tested:All-equal raster with auto-levels.
test_no_contours_flatpasses explicitlevels=[], so it never exercises the auto-level branch (levels=None) on a flat raster wherevmin == vmax. That branch callsnp.linspace(vmin, vmax, n_levels + 2)[1:-1]which produces identical levels on equal min/max — the function returns an empty result, but no test asserts this.Empty
levels=[]. Passing an empty list aslevelsreturns[]silently. No test documents that this is the intended behavior or that it does not raise.Proposal
Design: Add two test functions to
xrspatial/tests/test_contour.py:Value: Covers two branches with zero test coverage, preventing regressions on the auto-level range computation and the empty-levels path that the geopandas empty-GeoDataFrame CRS fix (#2700) depends on.
Stakeholders and Impacts
Test-only change. No source modification needed.
Drawbacks
Negligible — two small deterministic tests.
Alternatives