Skip to content

resample: add type annotations to public signature #2544

@brendancol

Description

@brendancol

API consistency sweep finding (Cat 3 MEDIUM)

The public resample() function in xrspatial/resample.py is the only public symbol from the resample module and is missing type annotations on every parameter and on the return type:

def resample(
    agg,
    scale_factor=None,
    target_resolution=None,
    method='nearest',
    nodata=None,
    name='resample',
):

Sibling modules in the terrain family (slope, aspect, hillshade, curvature) all annotate agg: xr.DataArray and declare -> xr.DataArray. Recent sweeps fixed the same gap in rasterize (#2250), polygonize (#2148), and open_geotiff (#2106). The docstring already declares the intended types so this is a doc-vs-signature drift, not new design work.

Impact

  • IDE autocompletion, mypy, and Sphinx autodoc silently lose information.
  • Users moving between resample and the annotated terrain family see inconsistent tooling support.

Fix

Add annotations matching the docstring and the @supports_dataset decorator contract:

def resample(
    agg: xr.DataArray,
    scale_factor: float | tuple[float, float] | None = None,
    target_resolution: float | tuple[float, float] | None = None,
    method: str = 'nearest',
    nodata: float | None = None,
    name: str = 'resample',
) -> xr.DataArray:

Also clarify in the docstring that agg accepts xr.Dataset too (the @supports_dataset decorator already handles it).

Notes on findings NOT filed

  • Cat 1 cross-module rename method vs resampling: resample(method=...) vs reproject(resampling=...) / merge(resampling=...). Same conceptual parameter, different name. Cross-cutting and would be a breaking rename in either direction. Documented in sweep state, not filed per-module per template.
  • Cat 1 first-arg name agg vs raster: Library-wide cross-cutting drift. Documented, not filed.

Test plan

  • Add a regression test mirroring test_rasterize_signature_annot_2250.py that pins every parameter and the return type as annotated.
  • Verify the existing 169 resample tests still pass.
  • Verify the cupy backend still accepts the same kwargs on a CUDA host.

cuda-validated: smoke-tested cupy backend with nearest, bilinear, and average methods on host with CUDA_AVAILABLE=True.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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