Describe the bug
contours() validates return_type too late. The only check is at the end of the
function (xrspatial/contour.py:691), inside the dispatch chain:
if return_type == "numpy":
return results
elif return_type == "geopandas":
...
else:
raise ValueError(...)
That runs only after the raster has been validated, the levels computed, and the
contours extracted. Two problems fall out of the ordering:
-
A bad return_type isn't rejected until the whole extraction has already run, so
the caller pays for work that was always going to fail.
-
The all-non-finite early return at xrspatial/contour.py:653-656 short-circuits
before that check ever happens:
if not np.isfinite(vmin) or not np.isfinite(vmax):
if return_type == "numpy":
return []
return _to_geopandas([], crs=agg.attrs.get('crs', None))
Any non-"numpy" value falls through to the GeoDataFrame branch. So
contours(all_nan_raster, return_type="bad") hands back an empty GeoDataFrame
instead of raising. The bad argument is silently accepted.
Expected behavior
return_type should be checked near the top of contours(), right after
_validate_raster and before any level computation or data work. A bad value should
raise ValueError no matter what the input raster looks like, including the
all-non-finite case.
Additional context
Fix: add an explicit return_type check (allowed values 'numpy' and 'geopandas')
at the top of the function. The existing late dispatch stays put but becomes
unreachable for bad values.
Describe the bug
contours()validatesreturn_typetoo late. The only check is at the end of thefunction (
xrspatial/contour.py:691), inside the dispatch chain:That runs only after the raster has been validated, the levels computed, and the
contours extracted. Two problems fall out of the ordering:
A bad
return_typeisn't rejected until the whole extraction has already run, sothe caller pays for work that was always going to fail.
The all-non-finite early return at
xrspatial/contour.py:653-656short-circuitsbefore that check ever happens:
Any non-
"numpy"value falls through to the GeoDataFrame branch. Socontours(all_nan_raster, return_type="bad")hands back an empty GeoDataFrameinstead of raising. The bad argument is silently accepted.
Expected behavior
return_typeshould be checked near the top ofcontours(), right after_validate_rasterand before any level computation or data work. A bad value shouldraise
ValueErrorno matter what the input raster looks like, including theall-non-finite case.
Additional context
Fix: add an explicit
return_typecheck (allowed values'numpy'and'geopandas')at the top of the function. The existing late dispatch stays put but becomes
unreachable for bad values.