interpolate: stop leaking template nodata sentinel onto float64 outputs#2
Open
jam-lock wants to merge 1 commit into
Open
interpolate: stop leaking template nodata sentinel onto float64 outputs#2jam-lock wants to merge 1 commit into
jam-lock wants to merge 1 commit into
Conversation
idw(), kriging(), and spline() copied `template.attrs` wholesale onto the float64 interpolation surface, leaking the template's nodata sentinel (e.g. `-9999` for an integer DEM template) onto a result whose actual no-data value is NaN (kriging, spline, and idw default) or the user's explicit `fill_value` (idw). Downstream code that read `result.attrs['nodatavals']` or `_FillValue` for masking saw a stale sentinel that no longer matched the data. Add `_validation._build_output_attrs` which strips inherited nodata keys, preserves spatial-reference attrs (`crs`, `res`, `transform`, extra coords), and re-emits the (`nodata`, `_FillValue`, `nodatavals`) triplet only when the actual fill value is non-NaN -- same pattern as the rasterize() fix in xarray-contrib#2018. Also tighten kriging's singular-matrix fallback to return a properly-named `{name}_variance` DataArray with attrs equal to the prediction's. 12 new tests in `TestMetadataPropagation` cover spatial-ref preservation, nodata-key stripping for the default NaN fill, triplet emission for explicit non-NaN fill, dims/coords preservation, the no-mutation contract on the caller's template.attrs, dask-vs-numpy attrs parity, and kriging variance/prediction attrs parity. CuPy and dask+cupy paths share the centralised public-API attrs construction so the fix applies uniformly; they were not executed here because CUDA is unavailable on this host.
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.
Summary
idw(),kriging(), andspline()previously copiedtemplate.attrswholesale onto the float64 interpolation output, leaking the template's nodata sentinel (e.g.-9999for an integer DEM template) onto a result whose actual no-data value is NaN (kriging/spline/idw-default) or the user's explicitfill_value(idw)._validation._build_output_attrshelper strips inherited nodata keys, preserves spatial-reference attrs (crs,res,transform, extra coords), and re-emits the (nodata,_FillValue,nodatavals) triplet only when the actual fill value is non-NaN. Same pattern as the rasterize() fix in rasterize: drop attrs, recompute coords, and don't emit _FillValue when like= is given xarray-contrib/xarray-spatial#2018.{name}_varianceDataArray with attrs that match the prediction's.Test plan
TestMetadataPropagationcovers spatial-ref preservation, nodata-key stripping for default NaN fill, triplet emission for explicit non-NaN fill, dims/coords preservation, no-mutation of caller'stemplate.attrs, dask-vs-numpy attrs parity, and kriging variance vs prediction attrs parity (12 tests).pytest xrspatial/tests/test_interpolation.py-- 48 passed, 5 skipped (CuPy).pytest xrspatial/tests/test_interpolation.py xrspatial/tests/test_rasterize.py-- 209 passed, 52 skipped, no regressions.xr.DataArray(...)call, so the fix applies uniformly. Re-validate on a GPU host before merge if desired.Found by
/deep-sweepmetadata sweep.