Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions xrspatial/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
import xarray as xr

from .utils import ArrayTypeFunctionMapping, ngjit
from .utils import ArrayTypeFunctionMapping, _validate_raster, ngjit

try:
import dask
Expand Down Expand Up @@ -602,8 +602,7 @@ def contours(
>>> # Each entry is (level_value, Nx2_coordinate_array)
>>> level, coords = lines[0]
"""
if agg.ndim != 2:
raise ValueError("Input raster must be 2D")
_validate_raster(agg, func_name='contours', name='agg', ndim=2)
if agg.shape[0] < 2 or agg.shape[1] < 2:
raise ValueError(
"Input raster must have at least 2 rows and 2 columns"
Expand Down
13 changes: 13 additions & 0 deletions xrspatial/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ def test_too_small(self):
with pytest.raises(ValueError, match="at least 2"):
contours(agg, levels=[0.5])

def test_complex_dtype_rejected(self):
"""Complex input raises instead of silently dropping the imaginary part."""
data = np.ones((3, 3), dtype=np.complex128)
agg = xr.DataArray(data, dims=['y', 'x'])
with pytest.raises(ValueError, match="real numeric"):
contours(agg, levels=[0.5])

def test_non_dataarray_rejected(self):
"""A plain ndarray raises a clear TypeError, not a late dispatch error."""
data = np.ones((3, 3), dtype=np.float64)
with pytest.raises(TypeError, match="xarray.DataArray"):
contours(data, levels=[0.5])


# ---------------------------------------------------------------------------
# Segment stitching
Expand Down
Loading