Describe the bug
resample masks input nodata sentinels to NaN before resampling. The non-identity path refreshes all three nodata-related attrs (_FillValue, nodatavals, nodata) to NaN so the metadata matches the masked data. The identity fast path (scale_factor=1.0) only refreshes _FillValue and leaves nodata and nodatavals pointing at the original integer sentinel.
The result advertises a finite sentinel that no longer appears in the data. Downstream consumers that trust attrs['nodata'] or attrs['nodatavals'] end up masking the wrong cells, or fail to mask the NaN cells.
Repro
import numpy as np, xarray as xr
from xrspatial.resample import resample
data = np.array([[-9999, -9999, 10, 10],
[-9999, -9999, 10, 10],
[20, 20, 30, 30],
[20, 20, 30, 30]], dtype=np.float32)
r = xr.DataArray(
data, dims=('y', 'x'),
coords={'y': np.linspace(3, 0, 4), 'x': np.linspace(0, 3, 4)},
attrs={'res': (1.0, 1.0), 'nodata': -9999, 'nodatavals': (-9999,)},
)
out = resample(r, scale_factor=1.0)
print(out.values[0, 0]) # nan
print(out.attrs['nodata']) # -9999 (stale)
print(out.attrs['nodatavals']) # (-9999,) (stale)
print(out.attrs['_FillValue']) # nan (correct)
Expected behavior
The identity fast path should refresh attrs['nodata'] and attrs['nodatavals'] to NaN, matching the non-identity path, whenever the nodata mask was applied. The 3D dispatch path has the same gap and should be fixed too.
Location
- Identity fast path:
xrspatial/resample.py around line 1387
- Non-identity reference behavior:
xrspatial/resample.py around line 1502
Describe the bug
resamplemasks input nodata sentinels to NaN before resampling. The non-identity path refreshes all three nodata-related attrs (_FillValue,nodatavals,nodata) to NaN so the metadata matches the masked data. The identity fast path (scale_factor=1.0) only refreshes_FillValueand leavesnodataandnodatavalspointing at the original integer sentinel.The result advertises a finite sentinel that no longer appears in the data. Downstream consumers that trust
attrs['nodata']orattrs['nodatavals']end up masking the wrong cells, or fail to mask the NaN cells.Repro
Expected behavior
The identity fast path should refresh
attrs['nodata']andattrs['nodatavals']to NaN, matching the non-identity path, whenever the nodata mask was applied. The 3D dispatch path has the same gap and should be fixed too.Location
xrspatial/resample.pyaround line 1387xrspatial/resample.pyaround line 1502