Skip to content

geotiff: write_vrt nodata type hint is float-only but to_geotiff/write_geotiff_gpu accept int #1684

@brendancol

Description

@brendancol

Summary

xrspatial.geotiff.write_vrt annotates its nodata kwarg as float | None:

def write_vrt(vrt_path: str, source_files: list[str], *,
              relative: bool = True,
              crs_wkt: str | None = None,
              nodata: float | None = None) -> str:

(xrspatial/geotiff/__init__.py:3421)

The sibling writers to_geotiff and write_geotiff_gpu leave nodata untyped and document it as accepting "float, int, or None". Integer sentinels (e.g. nodata=65535 for a uint16 raster, nodata=-9999 for an int32 raster) are common and pass through the rest of the I/O surface, but on write_vrt they violate the declared type and trip strict type checkers / IDEs.

Within _vrt.py, the underlying write_vrt (xrspatial/geotiff/_vrt.py:595) has the same float-only annotation and is rendered into a generic <NoDataValue>{nodata}</NoDataValue> XML element with str() formatting, so an int value is rendered without complaint at runtime.

Proposed fix

Widen the nodata type annotation on both the public wrapper (xrspatial/geotiff/__init__.py:3424) and the internal implementation (xrspatial/geotiff/_vrt.py:598). Either match the to_geotiff/write_geotiff_gpu style (drop the annotation, document the type in the docstring) or annotate as float | int | None. Update the docstring in both places to read "float, int, or None" so the surface lines up with the other writers.

Found during the geotiff API consistency sweep (Cat 3, MEDIUM).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions