diff --git a/xrspatial/surface_distance.py b/xrspatial/surface_distance.py index dd2bf33b7..fcb46cb19 100644 --- a/xrspatial/surface_distance.py +++ b/xrspatial/surface_distance.py @@ -1383,6 +1383,9 @@ def _compute(raster, elevation, x, y, target_values, max_distance, signed_cellsize_x = cellsize_x * _coord_step_sign(raster, x) signed_cellsize_y = cellsize_y * _coord_step_sign(raster, y) + if target_values is None: + target_values = [] + target_values = np.asarray(target_values, dtype=np.float64) if target_values.ndim != 1: raise ValueError( @@ -1528,7 +1531,7 @@ def surface_distance( elevation: xr.DataArray, x: str = "x", y: str = "y", - target_values: list = [], + target_values: list = None, max_distance: float = np.inf, connectivity: int = 8, method: str = 'planar', @@ -1584,7 +1587,7 @@ def surface_allocation( elevation: xr.DataArray, x: str = "x", y: str = "y", - target_values: list = [], + target_values: list = None, max_distance: float = np.inf, connectivity: int = 8, method: str = 'planar', @@ -1621,7 +1624,7 @@ def surface_direction( elevation: xr.DataArray, x: str = "x", y: str = "y", - target_values: list = [], + target_values: list = None, max_distance: float = np.inf, connectivity: int = 8, method: str = 'planar', diff --git a/xrspatial/tests/test_surface_distance.py b/xrspatial/tests/test_surface_distance.py index 499b689ea..b925215c5 100644 --- a/xrspatial/tests/test_surface_distance.py +++ b/xrspatial/tests/test_surface_distance.py @@ -613,6 +613,16 @@ def test_invalid_target_values_shape(bad): surface_distance(source, elev, target_values=bad) +@pytest.mark.parametrize("func", [surface_distance, surface_allocation, surface_direction]) +def test_target_values_none_matches_empty(func): + """target_values=None must behave like the [] default (issue #3712).""" + source = _make_raster(np.array([[0.0, 1.0, 0.0, 2.0, 0.0]], dtype=np.float64)) + elev = _make_raster(np.zeros((1, 5), dtype=np.float64)) + expected = _compute(func(source, elev)) + got = _compute(func(source, elev, target_values=None)) + np.testing.assert_array_equal(np.asarray(got), np.asarray(expected)) + + # --------------------------------------------------------------------------- # Tests — dask-specific # ---------------------------------------------------------------------------