Potential bug in interp
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What happened?
There seems to be an issue with dtypes when calling interp on dask-backed data arrays.
Example:
da = xr.DataArray(
data=dask.array.array([1, 2, 3], dtype=np.float32),
dims=("x"),
coords={"x": np.array([0, 1, 2], dtype=np.float32)},
)
da = da.interp(x=np.array([0.75], dtype=np.float64))
print(da.dtype, da.compute().dtype, da.astype(np.float32).compute().dtype)
this prints out:
float32 float64 float64
so, not only is there a difference before/after compute(), explicitly casting to float32 doesn't seem to have an effect.
What did you expect to happen?
No response
Minimal Complete Verifiable Example
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.11.8 (stable, redacted, redacted) [Clang 9999.0.0 (799e9053641a6478d3144866a97737b37b87c260)]
python-bits: 64
OS: Linux
OS-release: 5.10.0-smp-1105.47.0.0
machine: x86_64
processor:
byteorder: little
LC_ALL: en_US.UTF-8
LANG: None
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.3
libnetcdf: 4.6.1
xarray: 2025.01.2
pandas: 2.2.3
numpy: 2.2.4
scipy: 1.13.1
netCDF4: 1.6.5
pydap: None
h5netcdf: 999
h5py: 3.11.0
zarr: 2.18.2
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: None
dask: 2024.8.2
distributed: None
matplotlib: 3.9.1
cartopy: 0+unknown
seaborn: 0.12.2
numbagg: None
fsspec: 2023.3.0
cupy: None
pint: 0.24.3
sparse: None
flox: None
numpy_groupies: None
setuptools: 0.dev0+unknown
pip: None
conda: None
pytest: None
mypy: None
IPython: 7.34.0
sphinx: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided interp example with the reported versions and compare the dtype before and after compute(), including the explicit astype call. Trace the interp entry point and its dask-backed execution path. The issue does not state the expected dtype, so confirm the intended behavior before adding a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100