geotiff: refuse non-numeric nodata / _FillValue early (#1973)#1983
Merged
Conversation
attrs['_FillValue']='missing' (or attrs['nodata']='missing', or a non-numeric nodata= kwarg) used to crash deep inside the writer with ``ufunc 'isnan' not supported``. The TypeError did not name the offending attribute and gave no hint that nodata was the cause. Add _validate_nodata_arg in _validation.py and call it from to_geotiff, _write_vrt_tiled, and write_geotiff_gpu so the kwarg path is checked at the boundary. Tighten _resolve_nodata_attr to raise ValueError naming the bad attr when attrs['nodata'] or attrs['_FillValue'] is non-numeric. The rioxarray-style attrs['nodatavals'] branch keeps its existing skip-on-non-numeric behaviour (per-band tuples often carry placeholder entries from arbitrary upstream pipelines, so a single bad entry should not block writing).
Contributor
Author
PR Review (self-review)Suggestions
Nits
What looks good
Checklist
|
…numeric nodatavals - add an isinstance(nodata, bool) guard to _validate_nodata_arg so the GPU and VRT writers refuse nodata=True with the same TypeError the eager writer already raises for #1911; previously float(True) == 1.0 silently coerced the bool past the numeric branch on those paths - warn (UserWarning) from _resolve_nodata_attr when every attrs['nodatavals'] entry is non-numeric, since a tuple with zero usable sentinels is more likely a user error than an intentional no-sentinel signal; return value stays None to honour the function's skip-on-non-numeric contract - factor the duplicate non-numeric error string used by the attrs['nodata'] and attrs['_FillValue'] branches into a shared _nodata_attr_non_numeric_msg helper - add regression tests for the bool branch (validator + eager / VRT / GPU entry points), the all-non-numeric warning, and the no-warn paths (usable entry present, all-NaN tuple)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1973.
Summary
_validate_nodata_argrejects non-numericnodata=kwargs at the writer entry point.to_geotiff,_write_vrt_tiled, andwrite_geotiff_gpuall call it before any downstreamnp.isnanusage._resolve_nodata_attrnow raisesValueErrornaming the offending attribute whenattrs['nodata']orattrs['_FillValue']is non-numeric, instead of returning the value verbatim and letting NumPy crash later with a generic ufunc TypeError.attrs['nodatavals'](rioxarray's per-band tuple) keeps its existing skip-on-non-numeric behaviour, since those values often come from arbitrary upstream pipelines and a single bad entry should not block writing.Test plan
xrspatial/geotiff/tests/test_nodata_validation_1973.pycovers_validate_nodata_arg,_resolve_nodata_attr(both attrs), the writer kwarg path, the_FillValueattr path, and the.vrtdispatch path.pytest xrspatial/geotiff/tests/— same 8 pre-existing failures as main, none related.