Skip to content
Draft
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
9 changes: 6 additions & 3 deletions xrspatial/surface_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions xrspatial/tests/test_surface_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand Down
Loading