xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Potential bug in interp

Open bbabenko opened this issue 6 months ago • 1 comments
trafficstars

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

  • [x] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [x] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [x] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [x] New issue — a search of GitHub Issues suggests this is not a duplicate.
  • [x] 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

bbabenko avatar May 14 '25 19:05 bbabenko

Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!

welcome[bot] avatar May 14 '25 19:05 welcome[bot]