Skip to content

Style: fix flake8/isort findings in cost_distance.py (#3339)#3350

Merged
brendancol merged 3 commits into
mainfrom
deep-sweep-style-cost_distance-2026-06-15
Jun 15, 2026
Merged

Style: fix flake8/isort findings in cost_distance.py (#3339)#3350
brendancol merged 3 commits into
mainfrom
deep-sweep-style-cost_distance-2026-06-15

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3339

Style cleanup of xrspatial/cost_distance.py against the project's flake8 (max-line-length=100) and isort (line_length=100) config.

Changes

  • Cat 3 (F401): removed from functools import partial (unused refactor leftover, not re-exported).
  • Cat 5 (mutable default): the public cost_distance() signature used target_values: list = []. Switched to a None sentinel normalized to [] in the body, matching how proximity.py was fixed in Style cleanup in xrspatial/proximity.py (flake8 F841/E128, isort, mutable default) #2725. The argument is reassigned via np.asarray before anything mutates it, so the shared list never actually leaked, but the pattern is now correct. Added two regression tests: one confirms the default produces identical results across calls, the other confirms target_values=None matches the empty default.
  • Cat 1 (E302): two blank lines before the @ngjit _heap_push definition.
  • Cat 1 (E127): fixed continuation-line over-indent in the _cost_distance_dask_cupy and _cost_distance_dask_iterative signatures.
  • Cat 4 (isort): xrspatial.dataset_support sorts before xrspatial.utils; the utils from-import reflows to 100 columns.

No behavioural change is intended for the Cat 1/3/4 fixes. The Cat 5 change preserves behaviour.

Backends

Style-only change, applies uniformly across numpy / cupy / dask+numpy / dask+cupy. The mutable-default fix is in the shared public entry point.

Test plan

  • flake8 clean on xrspatial/cost_distance.py
  • isort --check-only clean on xrspatial/cost_distance.py
  • 57 cost_distance tests pass (CUDA available), including the two new regression tests

Pre-existing lint in test_cost_distance.py (F401, E201, isort drift) was left untouched as out of scope for this module sweep.

Categories addressed:
- Cat 3 (F401): remove unused `from functools import partial` (refactor
  leftover; not re-exported)
- Cat 5 (mutable default): public `cost_distance(target_values=[])` ->
  `None` sentinel normalized to `[]` in the body, mirroring proximity.py
  (#2725). Reassigned via np.asarray before any mutation, so behaviour is
  preserved. Adds regression tests covering default reuse and None.
- Cat 1 (E302): two blank lines before `@ngjit _heap_push`
- Cat 1 (E127): fix continuation-line over-indent in
  _cost_distance_dask_cupy and _cost_distance_dask_iterative signatures
- Cat 4 (isort): dataset_support before utils; utils from-import reflowed
  to 100 cols

No behavioural change for the Cat 1/3/4 fixes. The Cat 5 change preserves
behaviour. flake8 and isort --check-only are clean on the module; 57
cost_distance tests pass.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Jun 15, 2026
…_distance-2026-06-15

# Conflicts:
#	xrspatial/tests/test_cost_distance.py
@brendancol brendancol merged commit 4debca2 into main Jun 15, 2026
7 checks passed
@brendancol brendancol deleted the deep-sweep-style-cost_distance-2026-06-15 branch June 25, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Style: fix flake8/isort findings in cost_distance.py (F401, E302, E127, isort, mutable default)

1 participant