Describe the bug
contours() in xrspatial/contour.py does not validate n_levels. When levels is not passed, n_levels goes straight into np.linspace(vmin, vmax, n_levels + 2), so bad values slip through and fail in confusing ways instead of raising a clear error:
n_levels=0: np.linspace(..., 2)[1:-1] returns an empty array, so you get no contours and no warning.
- Negatives:
np.linspace raises a low-level error about a negative number of samples that never mentions n_levels.
- Floats like
2.5: np.linspace accepts the float count (n_levels + 2), so the failure surfaces deep in numpy.
- Booleans:
True/False are silently treated as 1/0, since bool subclasses int.
Expected behavior
n_levels should be a positive integer. Validate it up front and raise a clear TypeError/ValueError that names n_levels for 0, negatives, non-integer floats, and bool inputs. A valid positive integer should behave exactly as before.
Additional context
This only matters on the levels is None path. When explicit levels are passed, n_levels is ignored.
Describe the bug
contours()inxrspatial/contour.pydoes not validaten_levels. Whenlevelsis not passed,n_levelsgoes straight intonp.linspace(vmin, vmax, n_levels + 2), so bad values slip through and fail in confusing ways instead of raising a clear error:n_levels=0:np.linspace(..., 2)[1:-1]returns an empty array, so you get no contours and no warning.np.linspaceraises a low-level error about a negative number of samples that never mentionsn_levels.2.5:np.linspaceaccepts the float count (n_levels + 2), so the failure surfaces deep in numpy.True/Falseare silently treated as1/0, sinceboolsubclassesint.Expected behavior
n_levelsshould be a positive integer. Validate it up front and raise a clearTypeError/ValueErrorthat namesn_levelsfor0, negatives, non-integer floats, and bool inputs. A valid positive integer should behave exactly as before.Additional context
This only matters on the
levels is Nonepath. When explicitlevelsare passed,n_levelsis ignored.