Describe the bug
contours() in xrspatial/contour.py checks the return_type argument only at the end of the function, after all the contour work has already run. The branch that raises ValueError for an unknown return_type sits near the bottom of the function (around line 676), past level generation, backend dispatch, and the per-segment coordinate transform.
For a Dask-backed input this means an invalid return_type triggers a full dask.compute() before the function raises. For a large NumPy raster it can hit the memory guard in _contours_numpy first. Either way the call does a lot of work before failing on what is usually a typo.
Expected behavior
An invalid return_type should fail fast with a clear ValueError before any level generation, backend dispatch, or compute happens. Passing return_type="geojson" (or any other unsupported value) should raise right away, with no Dask execution and no memory allocation.
Steps to reproduce
- Build a Dask-backed DataArray.
- Call
contours(agg, return_type="bogus").
- The chunks get computed before the
ValueError is raised.
Additional context
Move the return_type membership check to the top of contours(), next to the existing raster validation. The late branch can then drop its else: raise since the value is already known good. Add a test asserting an invalid return_type raises without triggering a compute on a Dask input.
Describe the bug
contours()inxrspatial/contour.pychecks thereturn_typeargument only at the end of the function, after all the contour work has already run. The branch that raisesValueErrorfor an unknownreturn_typesits near the bottom of the function (around line 676), past level generation, backend dispatch, and the per-segment coordinate transform.For a Dask-backed input this means an invalid
return_typetriggers a fulldask.compute()before the function raises. For a large NumPy raster it can hit the memory guard in_contours_numpyfirst. Either way the call does a lot of work before failing on what is usually a typo.Expected behavior
An invalid
return_typeshould fail fast with a clearValueErrorbefore any level generation, backend dispatch, or compute happens. Passingreturn_type="geojson"(or any other unsupported value) should raise right away, with no Dask execution and no memory allocation.Steps to reproduce
contours(agg, return_type="bogus").ValueErroris raised.Additional context
Move the
return_typemembership check to the top ofcontours(), next to the existing raster validation. The late branch can then drop itselse: raisesince the value is already known good. Add a test asserting an invalidreturn_typeraises without triggering a compute on a Dask input.