Describe the bug
resample() casts every input to float64 internally and emits float32 regardless of input dtype. That silently throws away precision for float64 rasters and forces an unnecessary copy when input is already float64.
import numpy as np, xarray as xr
from xrspatial.resample import resample
data = np.linspace(0, 1, 64 * 64, dtype=np.float64).reshape(64, 64)
da = xr.DataArray(
data, dims=('y', 'x'),
coords={'y': np.arange(64), 'x': np.arange(64)},
attrs={'res': (1.0, 1.0)},
)
out = resample(da, scale_factor=0.5)
print(out.dtype) # float32 -- precision lost
Expected behavior
- float64 input gives float64 output (no silent precision loss).
- float32 input gives float32 output (existing default).
- integer input gives float32 output, since NaN-sentinel resampling needs a float type.
Proposal
Pick a working dtype inside each _run_* runner: float64 if input itemsize is at least 8, else float32. Skip the astype copy when input dtype already matches. Apply the same rule across all four backend runners (_run_numpy, _run_cupy, _run_dask_numpy, _run_dask_cupy).
Output dtype:
- float input: match input dtype.
- integer input: float32.
Update the docstring return-type description to match.
Tests
- float64 input gives float64 output, values match a high-precision reference (atol=1e-12).
- float32 input gives float32 output.
- int32 input gives float32 output.
- Dask paths follow the same rules.
Describe the bug
resample()casts every input tofloat64internally and emitsfloat32regardless of input dtype. That silently throws away precision forfloat64rasters and forces an unnecessary copy when input is alreadyfloat64.Expected behavior
Proposal
Pick a working dtype inside each
_run_*runner: float64 if input itemsize is at least 8, else float32. Skip theastypecopy when input dtype already matches. Apply the same rule across all four backend runners (_run_numpy,_run_cupy,_run_dask_numpy,_run_dask_cupy).Output dtype:
Update the docstring return-type description to match.
Tests