Skip to content

geotiff: non-numeric _FillValue crashes with opaque TypeError from np.isnan #1973

@brendancol

Description

@brendancol

Describe the bug

xrspatial/geotiff/_attrs.py:228 returns a non-numeric _FillValue verbatim with a comment that this is intentional pass-through. Later, xrspatial/geotiff/_writers/eager.py:654 calls np.isnan(nodata), which raises a TypeError with no reference to the offending attribute.

Reproduction

import numpy as np, xarray as xr, tempfile
from xrspatial.geotiff import to_geotiff

da = xr.DataArray(np.full((4,4), np.nan, dtype=np.float32),
                  coords={'y': np.arange(4), 'x': np.arange(4)},
                  dims=('y','x'),
                  attrs={'_FillValue': 'missing'})
with tempfile.NamedTemporaryFile(suffix='.tif') as f:
    to_geotiff(da, f.name)
# TypeError: ufunc 'isnan' not supported for the input types,
# and the inputs could not be safely coerced to any supported
# types according to the casting rule ''safe''

Expected behavior

_resolve_nodata should reject a non-numeric _FillValue (or nodata) at the validation boundary with a clear ValueError naming the attribute, the value, and that nodata must be numeric. The nodatavals branch already filters non-numeric entries; the _FillValue branch should do the same instead of relying on a downstream NumPy ufunc to crash.

Additional context

Found in a code review of the geotiff module alongside #1971 and #1972.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginput-validationInput validation and error messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions