surface_distance.py fails the project isort check

Open Beginner friendly
#3,710 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
tooling

Research direction

Start with xrspatial/surface_distance.py and run python -m isort --check-only --diff xrspatial/surface_distance.py using the line_length = 100 setting in setup.cfg. Compare the import layout with cost_distance.py, proximity.py, focal.py, and zonal.py. Done means the imports are reordered only, with the isort check passing and no names or runtime behavior changed.

Written by the indexing model from the issue text.

Description

xrspatial/surface_distance.py fails the project's isort check. setup.cfg configures isort with line_length = 100, but no CI job runs it, so the drift went unnoticed.

Reproduction

$ python -m isort --check-only --diff xrspatial/surface_distance.py
ERROR: xrspatial/surface_distance.py Imports are incorrectly sorted and/or formatted.
--- xrspatial/surface_distance.py:before
+++ xrspatial/surface_distance.py:after
@@ -47,15 +47,12 @@
-from xrspatial.cost_distance import _heap_push, _heap_pop
+from xrspatial.cost_distance import _heap_pop, _heap_push
+from xrspatial.dataset_support import supports_dataset
 from xrspatial.proximity import _vectorized_calc_direction
-from xrspatial.utils import (
-    _validate_raster,
-    cuda_args, get_dataarray_resolution, ngjit,
-    has_cuda_and_cupy, is_cupy_array, is_dask_cupy,
-)
-from xrspatial.dataset_support import supports_dataset
-from xrspatial.utils import _dask_task_name_kwargs
+from xrspatial.utils import (_dask_task_name_kwargs, _validate_raster, cuda_args,
+                             get_dataarray_resolution, has_cuda_and_cupy, is_cupy_array,
+                             is_dask_cupy, ngjit)

Three things are off:

  1. _heap_push, _heap_pop are out of alphabetical order.
  2. xrspatial.utils is imported twice, in two statements separated by an unrelated import.
  3. The wrapped xrspatial.utils block uses a hanging-indent style that its nearest neighbours do not. cost_distance.py, proximity.py, focal.py and zonal.py all already carry the exact layout isort wants here, so this file is the outlier among the modules it borrows from.

flake8 is clean on this file (0 violations), so this is purely the isort side.

Scope

Import reordering only. No runtime behaviour change, no names added or removed.

Found by a style sweep of surface_distance. Two smaller things turned up that are not worth a code change on their own, noted here so nobody has to rediscover them:

  • _surface_distance_dask unpacks height, width = source_da.shape and never uses either name. pyflakes skips F841 for tuple unpacking, so flake8 misses it.
  • _precompute_dd_grid imports _available_memory_bytes from xrspatial.zonal even though this module defines its own copy of that helper at the top. Both work; the local one is right there.
Dominant language
Python
Stars
972
Forks
92
Avg merge
2d 12h
Merged PRs (30d)
7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xarray-contrib/xarray-spatial

All issues in xarray-contrib/xarray-spatial

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.