Describe the bug
polygonize's simplify_tolerance only rejects negative values. Non-finite values slip through:
nan: silently disables simplification. The gating check is simplify_tolerance > 0, which is False for nan, so the call returns unsimplified polygons even though the caller asked for simplification.
inf (positive): collapses every polygon to nothing and returns empty output.
-inf: caught by the existing < 0 check, but only by accident of the sign.
The same module already validates atol and rtol as finite + non-negative. simplify_tolerance should follow the same pattern.
Expected behavior
Passing simplify_tolerance=nan, simplify_tolerance=inf, or simplify_tolerance=-inf should raise ValueError with a clear message, matching the existing atol/rtol validation.
Reproducer
import numpy as np
import xarray as xr
from xrspatial import polygonize
raster = xr.DataArray(np.array([[0, 1], [1, 0]], dtype=np.float32))
polygonize(raster, simplify_tolerance=float('nan')) # silently no-op, should raise
polygonize(raster, simplify_tolerance=float('inf')) # empty output, should raise
Fix
Mirror the atol/rtol validation block at xrspatial/polygonize.py:2013 and apply it to simplify_tolerance at xrspatial/polygonize.py:1999.
Additional context
Surfaced during an input-validation audit of polygonize.
Describe the bug
polygonize'ssimplify_toleranceonly rejects negative values. Non-finite values slip through:nan: silently disables simplification. The gating check issimplify_tolerance > 0, which isFalsefornan, so the call returns unsimplified polygons even though the caller asked for simplification.inf(positive): collapses every polygon to nothing and returns empty output.-inf: caught by the existing< 0check, but only by accident of the sign.The same module already validates
atolandrtolas finite + non-negative.simplify_toleranceshould follow the same pattern.Expected behavior
Passing
simplify_tolerance=nan,simplify_tolerance=inf, orsimplify_tolerance=-infshould raiseValueErrorwith a clear message, matching the existingatol/rtolvalidation.Reproducer
Fix
Mirror the
atol/rtolvalidation block atxrspatial/polygonize.py:2013and apply it tosimplify_toleranceatxrspatial/polygonize.py:1999.Additional context
Surfaced during an input-validation audit of
polygonize.