From 7dacd485b5252577db4c47290a536c88a36fe3dd Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Sat, 20 Jun 2026 02:52:16 -0700 Subject: [PATCH] morphology: remove unused imports and dead local, fix import order Resolves the style-sweep findings for xrspatial/morphology.py (#3400). Cat 3 (F-codes): - F401: drop unused imports xarray as xr (only DataArray is used), has_cuda_and_cupy, and not_implemented_func. - F841: drop the unused local size in _circle_kernel. Cat 4 (isort): normalize import ordering with isort under line_length=100. None of the removed names are re-exported (__init__ exports only the public morph_* functions), so there is no behavior change. flake8 and isort are clean and the 74 morphology tests pass. --- .claude/sweep-style-state.csv | 1 + xrspatial/morphology.py | 22 +++++----------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.claude/sweep-style-state.csv b/.claude/sweep-style-state.csv index 34775463d..49b605efd 100644 --- a/.claude/sweep-style-state.csv +++ b/.claude/sweep-style-state.csv @@ -9,6 +9,7 @@ hydro-d8,2026-05-29,2705,HIGH,1;3;4,"flake8+isort over the 13 D8 files only (din interpolate,2026-06-12,3286,HIGH,3;4,"Full subpackage sweep (_idw, _kriging, _spline, _validation). Cat 3 F401: unused 'import math' in _idw.py L5 (IDW kernels are pure arithmetic; _spline.py keeps math for math.log in TPS kernels; not re-exported, __init__ exports only idw/kriging/spline). Cat 4 isort: _idw.py + _spline.py 5-line xrspatial.utils from-import reflowed to 2 lines under line_length=100, matching _kriging.py from #2916. Cat 1/2/5 clean (no E/W codes; grep: no bare except, mutable defaults, ==None/True, shadowed builtins). flake8+isort clean after fix; 66 interpolation tests pass (CUDA available). PR open." interpolate-kriging,2026-06-04,2916,MEDIUM,1;4,"flake8 E128 x2: continuation-line under-indent at the _chunk_var kriging-predict calls in _kriging_dask_numpy (L234) and _kriging_dask_cupy (L324); re-indented to visual-indent column. Cat 4 isort: 5-line from xrspatial.utils (...) block collapses to one 88-char line under line_length=100. Cat 2/3/5 grep clean (no W-codes, F-codes, bare except, mutable defaults, ==None/True, or shadowed builtins). flake8+isort clean after fix; 14 kriging tests pass. PR open." mcda,2026-06-10,3143,HIGH,3;4,F401 dead function-local warnings import in standardize.py; isort drift in weights.py combine.py __init__.py; flake8 otherwise clean; Cat 5 greps clean; fixed via PR for #3143 +morphology,2026-06-20,3400,HIGH,3;4,"F401 xr/has_cuda_and_cupy/not_implemented_func + F841 size (dead); isort ordering. /rockout PR off issue 3400. flake8+isort clean, 74 tests pass." polygon_clip,2026-06-10,3184,HIGH,3;4,"Cat 3 F401: dropped unused typing imports Sequence/Tuple/Union (line 10, only Optional used) and the dead 'import cupy' inside the _apply_mask dask+cupy closure (line 245); the other 'import cupy' at line 261 is used (cupy.asarray) and kept. None re-exported (__init__ re-exports only clip_polygon). Cat 4 isort: reflowed the 5-name xrspatial.utils from-import block to line_length=100. Cat 1/2/5 grep clean (no E/W codes, no bare except, mutable defaults, ==None/True, or shadowed builtins). flake8+isort clean after fix; 23 test_polygon_clip tests pass. PR open." polygonize,2026-05-27,2534,HIGH,1;3;4,"F401 line 58 (is_cupy_array unused, not re-exported). E127 lines 83/88 (overload continuation indent in generated_jit). isort: 5-line .utils import block collapses to one line at 100-char limit. Cat 2 clean. Cat 5 grep clean." proximity,2026-05-29,2725,HIGH,1;3;4;5,"F841 line 1274 original_chunks dead local in unbounded dask+cupy branch (refactor leftover). Cat 5 mutable default target_values: list = [] in proximity/allocation/direction -> None sentinel, normalized to [] in body (never mutated, behaviour preserved). E128 line 291 np.where continuation under-indent in _vectorized_calc_direction. isort: re-sorted xrspatial import block + blank line after inline import cupy as cp. flake8+isort clean after fix; 69 proximity tests pass + new parametrized regression test. Pre-existing E127 (test_proximity.py 726/752) + test-file isort drift left untouched (out of module scope)." diff --git a/xrspatial/morphology.py b/xrspatial/morphology.py index 87c01bb95..51b416561 100644 --- a/xrspatial/morphology.py +++ b/xrspatial/morphology.py @@ -16,10 +16,8 @@ from functools import partial import numpy as np -import xarray as xr -from xarray import DataArray - from numba import cuda, prange +from xarray import DataArray try: import cupy @@ -32,25 +30,16 @@ class cupy: except ImportError: da = None -from xrspatial.utils import ( - ArrayTypeFunctionMapping, - _boundary_to_dask, - _dask_task_name_kwargs, - _pad_array, - _validate_boundary, - _validate_raster, - calc_cuda_dims, - has_cuda_and_cupy, - ngjit, - not_implemented_func, -) from xrspatial.dataset_support import supports_dataset - +from xrspatial.utils import (ArrayTypeFunctionMapping, _boundary_to_dask, _dask_task_name_kwargs, + _pad_array, _validate_boundary, _validate_raster, calc_cuda_dims, + ngjit) # --------------------------------------------------------------------------- # Memory guard # --------------------------------------------------------------------------- + def _available_memory_bytes(): """Best-effort estimate of available memory in bytes.""" # Try /proc/meminfo (Linux) @@ -103,7 +92,6 @@ def _circle_kernel(radius): The kernel has shape ``(2*radius+1, 2*radius+1)`` with ``True`` for cells whose centre is within *radius* cells of the centre. """ - size = 2 * radius + 1 y, x = np.ogrid[-radius:radius + 1, -radius:radius + 1] return (x * x + y * y <= radius * radius).astype(np.uint8)