Skip to content

Add test for cost_distance dask all-impassable early return (#3367)#3368

Merged
brendancol merged 2 commits into
mainfrom
deep-sweep-test-coverage-cost_distance-2026-06-16
Jun 17, 2026
Merged

Add test for cost_distance dask all-impassable early return (#3367)#3368
brendancol merged 2 commits into
mainfrom
deep-sweep-test-coverage-cost_distance-2026-06-16

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3367

What

Adds one test (test_dask_all_impassable_friction_returns_nan) covering the f_min <= 0 early return in _cost_distance_dask. When friction has no passable cell and max_cost is finite, that branch short-circuits to da.full(..., nan) and keeps the input chunking, instead of running map_overlap or the iterative tile Dijkstra. Nothing reached this branch before.

The test builds an all-zero-friction dask+numpy raster with max_cost=5.0 and asserts the result is all-NaN, dask-backed, and keeps more than one partition.

Backend coverage

Test-only change, dask+numpy path. Source untouched.

Test plan

  • test_dask_all_impassable_friction_returns_nan passes
  • -W error::UserWarning confirms the early return is taken (no "iterative tile Dijkstra" warning)
  • Full test_cost_distance.py green on a CUDA host (85 passed)

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Add test for cost_distance dask all-impassable early return (#3367)

Blockers

None.

Suggestions

None.

Nits

None.

What looks good

  • The test hits the intended branch. All-zero friction makes da.where(friction_da > 0, friction_da, np.inf) all-inf, so da.nanmin returns inf, np.isfinite(f_min) is False, and _cost_distance_dask takes the da.full(..., np.nan) early return at cost_distance.py:1150 instead of map_overlap or the iterative tile Dijkstra.
  • The three assertions match that branch's contract: all-NaN output, dask-backed result, npartitions > 1 (chunking preserved).
  • The PR proves the early return is reached via -W error::UserWarning. The iterative path raises a UserWarning, so its absence pins the branch and stops the test from silently drifting onto the iterative path later.
  • Test-only change, source untouched. No backend-parity or numerical-correctness risk.

Checklist

  • NaN handling correct: yes (asserts all-NaN)
  • Edge case covered: yes (adds the missing all-impassable dask case)
  • Dask chunking handled: yes (asserts npartitions > 1)
  • No premature materialization: yes (single _compute at the end)
  • Benchmark: not needed (test-only)
  • Docstring present: yes (explains the branch)

@brendancol brendancol merged commit 2aa9060 into main Jun 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cost_distance: dask all-impassable early-return branch is untested

1 participant