Skip to content

Style cleanup in focal.py: unused import, isort drift, mutable default arg #2731

@brendancol

Description

@brendancol

What

Three style issues in xrspatial/focal.py, all flagged by the project's own setup.cfg config (flake8, isort) plus a grep for mutable default arguments. None of them change behaviour.

1. Unused import (flake8 F401)

Line 36 imports not_implemented_func from xrspatial.utils and never uses it. There's no __all__ and nothing imports it from xrspatial.focal, so it's not a re-export -- just a leftover from an earlier refactor.

2. Import ordering (isort)

The import block at the top of the file doesn't match the project's isort config (line_length=100). The stdlib imports are interleaved (import copy / from functools import partial / from math import isnan / import math), there's a stray blank line inside a grouped block, and the from-imports for xrspatial.convolution and xrspatial.utils aren't alphabetised or wrapped to the configured width. The xrspatial.dataset_support import is also out of order.

3. Mutable default argument

mean(agg, passes=1, excludes=[np.nan], ...) uses a list literal as a default. The list is never mutated here -- it's only iterated and passed through tuple() -- so behaviour is correct today. But a shared mutable default is a footgun, and the style sweep flags it. Fix is the usual sentinel: default to None, assign [np.nan] in the body. Same behaviour, plus a regression test that the default doesn't leak across calls.

Scope

xrspatial/focal.py and a test in xrspatial/tests/test_focal.py. No config widening, no autoformatter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfocal toolsFocal statistics and hotspot analysis

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions