Skip to content

proximity: style cleanup (flake8 F841/E128, isort, mutable default)#2729

Open
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-style-proximity-2026-05-29
Open

proximity: style cleanup (flake8 F841/E128, isort, mutable default)#2729
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-style-proximity-2026-05-29

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #2725

Style sweep cleanup for xrspatial/proximity.py. Four findings from flake8 (max-line-length=100) and isort (line_length=100), bundled into one pass.

What changed

  • Cat 3 (F841): removed the dead local original_chunks in the unbounded dask+cupy branch. It was assigned and never read, a leftover from when chunk geometry used to be restored after the cupy-to-numpy conversion.
  • Cat 5 (mutable default): proximity, allocation, and direction declared target_values: list = []. Switched to a None sentinel and normalize to [] at the top of each function body. The old default was never mutated, so this preserves behaviour while dropping the shared-mutable-default anti-pattern.
  • Cat 1 (E128): reflowed the under-indented np.where continuation in _vectorized_calc_direction.
  • Cat 4 (isort): re-sorted the xrspatial import block and added the blank line isort wants after the inline import cupy as cp.

After the change, flake8 xrspatial/proximity.py and isort --check-only xrspatial/proximity.py both pass clean.

Behaviour

No behavioural change intended. The E128 reflow and isort reordering are formatting only, the F841 removal deletes dead code, and the mutable-default fix is behaviour-preserving (None normalizes to []).

Backends

Static source-level changes, uniform across numpy / cupy / dask+numpy / dask+cupy. No backend-specific logic touched.

Test plan

  • flake8 xrspatial/proximity.py clean
  • isort --check-only xrspatial/proximity.py clean
  • Existing suite: pytest xrspatial/tests/test_proximity.py (69 passed)
  • Added regression test: None default matches explicit [] for all three public functions

Note: test_proximity.py carries two pre-existing E127 warnings (lines 726, 752) and isort import drift that predate this PR. Left untouched to keep the diff scoped to the audited module.

…2725)

- Remove dead local original_chunks in the unbounded dask+cupy branch (F841).
- Switch target_values default from [] to a None sentinel in proximity,
  allocation, and direction; normalize to [] in the body so behaviour is
  unchanged (mutable-default anti-pattern).
- Reflow under-indented np.where continuation in _vectorized_calc_direction
  (E128).
- Re-sort the xrspatial import block and add the isort-required blank line
  after the inline `import cupy as cp` (Cat 4).

No behavioural change. Adds a regression test asserting the None default
matches an explicit empty list for all three public functions.

Closes #2725
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 29, 2026
Copy link
Copy Markdown
Contributor Author

@brendancol brendancol left a comment

Choose a reason for hiding this comment

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

PR Review: proximity style cleanup (flake8 F841/E128, isort, mutable default)

Blockers (must fix before merge)

None.

Suggestions (should fix, not blocking)

None.

Nits (optional improvements)

  • The annotation is now target_values: list = None, which really describes an Optional[list]. The strictly correct form would be Optional[list], but list = None is common shorthand in this codebase and the body normalizes immediately, so it is fine as-is. Not worth changing unless the project decides to standardize on Optional.

What looks good

  • The F841 removal is safe: original_chunks had a single occurrence and was never read.
  • The mutable-default fix preserves behaviour. The old [] default was never mutated, and None normalizes to [] at the top of each public function before any use.
  • The E128 reflow and isort reordering are formatting only, confirmed clean by both linters.
  • The regression test covers all three public functions via parametrize and asserts the None default matches an explicit empty list.
  • The diff stays scoped to the audited module. Pre-existing lint in the test file was correctly left alone.

Checklist

  • Algorithm unchanged (no logic touched)
  • All backends: static source change, uniform across numpy/cupy/dask
  • NaN handling unchanged
  • Edge cases: existing 69 tests pass, new regression test added
  • Dask chunk boundaries not touched
  • No premature materialization introduced
  • Benchmark not needed (no perf change)
  • README feature matrix not applicable (no new function)
  • Docstrings present and unchanged

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 cleanup in xrspatial/proximity.py (flake8 F841/E128, isort, mutable default)

1 participant