Skip to content

Possible performance regression in interp() behaviour #10287

Closed
@leroyvn

Description

@leroyvn

What happened?

I am interpolating on a single dimension in a somewhat large dataset (a few 100s MB). Prior to updating xarray to 2025.1, I was using DataArray.interp() on a lazy-loaded dataset (open with open_dataset()) with a given interpolation time. Since upgrading to 2025.1, the interpolation time has massively increased, destroying the performance of my application.

What did you expect to happen?

I would expect the interpolation time to remain similar.

Minimal Complete Verifiable Example

This self-contained example behaves similarly to my use case (the hit is not as bad as in my actual use case, but it is quite representative).

import timeit

import xarray as xr
import numpy as np


ds = xr.Dataset(
    {
        "sigma_a": xr.DataArray(
            data=np.ones((4, 2, 2, 16, 8, 36811)),
            dims=["x_H2O", "x_CO2", "x_O3", "p", "t", "w"],
            coords={"w": np.linspace(0, 30000, 36811)},
        )
    }
)
ds.to_netcdf("komodo.nc")
ds.close()
print(ds["w"].values)
del ds

w = 15000.5

ds = xr.load_dataset("komodo.nc")
duration = timeit.timeit(lambda: ds["sigma_a"].interp(w=w), number=10)
print(f"load_dataset(): {duration} s")

with xr.open_dataset("komodo.nc") as ds:
    duration = timeit.timeit(lambda: ds["sigma_a"].interp(w=w), number=10)
    print(f"open_dataset(): {duration} s")

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

Console output with xarray 2024.11:

load_dataset(): 3.032241018023342 s
open_dataset(): 0.17071856604889035 s

Console output with xarray 2025.1:

load_dataset(): 3.0386892098467797 s
open_dataset(): 1.0940946410410106 s

Anything else we need to know?

No response

Environment

Tested with Python 3.10 to 3.12, in an environment with SciPy and NetCDF4 installed, with NumPy 1 and 2.

2024 env example
INSTALLED VERSIONS
------------------
commit: None
python: 3.12.10 | packaged by conda-forge | (main, Apr 10 2025, 22:21:13) [GCC 13.3.0]
python-bits: 64
OS: Linux
OS-release: 6.8.0-57-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: ('en_GB', 'UTF-8')
libhdf5: 1.14.2
libnetcdf: 4.9.4-development

xarray: 2024.11.0
pandas: 2.2.3
numpy: 2.2.5
scipy: 1.15.2
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.4.post1
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: None
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None
2025 env example
INSTALLED VERSIONS
------------------
commit: None
python: 3.12.10 | packaged by conda-forge | (main, Apr 10 2025, 22:21:13) [GCC 13.3.0]
python-bits: 64
OS: Linux
OS-release: 6.8.0-57-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: ('en_GB', 'UTF-8')
libhdf5: 1.14.2
libnetcdf: 4.9.4-development

xarray: 2025.1.2
pandas: 2.2.3
numpy: 2.2.5
scipy: 1.15.2
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.4.post1
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: None
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions