From f560a5386116e257f97c2f9f3880c777017c9dca Mon Sep 17 00:00:00 2001 From: Melissari1997 Date: Sun, 7 Jun 2026 10:23:38 +0200 Subject: [PATCH 1/2] Add tests for all-NaN auto-levels RuntimeWarning regression (#2795) --- xrspatial/tests/test_contour.py | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/xrspatial/tests/test_contour.py b/xrspatial/tests/test_contour.py index 073842a9..b95c5d36 100644 --- a/xrspatial/tests/test_contour.py +++ b/xrspatial/tests/test_contour.py @@ -120,6 +120,70 @@ 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).""" + import warnings + 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).""" + import warnings + 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).""" + import warnings + 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).""" + import warnings + 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) From 136132f8d6a5fc1d6db26fbf0010a50ee426450f Mon Sep 17 00:00:00 2001 From: Melissari1997 Date: Sun, 7 Jun 2026 10:26:42 +0200 Subject: [PATCH 2/2] Address review nit: move import warnings to module level (#2795) --- xrspatial/tests/test_contour.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/xrspatial/tests/test_contour.py b/xrspatial/tests/test_contour.py index b95c5d36..0d4300df 100644 --- a/xrspatial/tests/test_contour.py +++ b/xrspatial/tests/test_contour.py @@ -1,3 +1,4 @@ +import warnings import numpy as np import pytest import xarray as xr @@ -122,7 +123,6 @@ def test_all_nan(self): def test_all_nan_auto_levels_no_warning(self): """All-NaN raster with auto levels must not emit RuntimeWarning (#2795).""" - import warnings 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: @@ -138,7 +138,6 @@ def test_all_nan_auto_levels_no_warning(self): @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).""" - import warnings 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: @@ -154,7 +153,6 @@ def test_all_nan_auto_levels_no_warning_dask(self): @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).""" - import warnings 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: @@ -171,7 +169,6 @@ def test_all_nan_auto_levels_no_warning_cupy(self): @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).""" - import warnings 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: