Skip to content
Open
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
61 changes: 61 additions & 0 deletions xrspatial/tests/test_contour.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import numpy as np
import pytest
import xarray as xr
Expand Down Expand Up @@ -120,6 +121,66 @@ def test_all_nan(self):
result = contours(agg, levels=[0.0])
assert result == []

def test_all_nan_auto_levels_no_warning(self):
"""All-NaN raster with auto levels must not emit RuntimeWarning (#2795)."""
data = np.full((4, 4), np.nan, dtype=np.float64)
agg = create_test_raster(data, backend='numpy')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
result = contours(agg)
assert result == []
runtime_warnings = [x for x in w if issubclass(x.category, RuntimeWarning)]
assert len(runtime_warnings) == 0, (
f"RuntimeWarning emitted on all-NaN auto-level path: "
f"{[str(x.message) for x in runtime_warnings]}"
)

@dask_array_available
def test_all_nan_auto_levels_no_warning_dask(self):
"""All-NaN dask raster with auto levels must not emit RuntimeWarning (#2795)."""
data = np.full((4, 4), np.nan, dtype=np.float64)
agg = create_test_raster(data, backend='dask+numpy', chunks=(2, 2))
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
result = contours(agg)
assert result == []
runtime_warnings = [x for x in w if issubclass(x.category, RuntimeWarning)]
assert len(runtime_warnings) == 0, (
f"RuntimeWarning emitted on all-NaN dask auto-level path: "
f"{[str(x.message) for x in runtime_warnings]}"
)

@cuda_and_cupy_available
def test_all_nan_auto_levels_no_warning_cupy(self):
"""All-NaN cupy raster with auto levels must not emit RuntimeWarning (#2795)."""
data = np.full((4, 4), np.nan, dtype=np.float64)
agg = create_test_raster(data, backend='cupy')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
result = contours(agg)
assert result == []
runtime_warnings = [x for x in w if issubclass(x.category, RuntimeWarning)]
assert len(runtime_warnings) == 0, (
f"RuntimeWarning emitted on all-NaN cupy auto-level path: "
f"{[str(x.message) for x in runtime_warnings]}"
)

@dask_array_available
@cuda_and_cupy_available
def test_all_nan_auto_levels_no_warning_dask_cupy(self):
"""All-NaN dask+cupy raster with auto levels must not emit RuntimeWarning (#2795)."""
data = np.full((4, 4), np.nan, dtype=np.float64)
agg = create_test_raster(data, backend='dask+cupy', chunks=(2, 2))
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
result = contours(agg)
assert result == []
runtime_warnings = [x for x in w if issubclass(x.category, RuntimeWarning)]
assert len(runtime_warnings) == 0, (
f"RuntimeWarning emitted on all-NaN dask+cupy auto-level path: "
f"{[str(x.message) for x in runtime_warnings]}"
)

def test_partial_nan(self):
"""Contours skip quads with NaN corners."""
data = _make_ramp(ny=5, nx=6)
Expand Down
Loading