Description
What happened:
Attempted to interpolate outside coordinate range while passing bounds_error=True
through kwargs
dictionary (which internally gets passed to scipy.interpolate.interp1d
). Instead if interp
function raising a ValueError
nans are returned.
What you expected to happen:
I expected a ValueError
exception to be raised when I've passed in the kwargs bounds_error=True
.
Minimal Complete Verifiable Example:
import xarray as xr
import numpy as np
da = xr.DataArray(
np.sin(0.3 * np.arange(12).reshape(4, 3)),
[("time", np.arange(4)), ("space", [0.1, 0.2, 0.3])],
)
# this should return nans, as the default is to fill with nans
da.interp(time=3.5)
> <xarray.DataArray (space: 3)>
> array([nan, nan, nan])
> Coordinates:
> * space (space) float64 0.1 0.2 0.3
> time float64 3.5
# this should raise ValueError, but `bounds_error` is ignored
da.interp(time=3.5, kwargs=dict(bounds_error=True))
> <xarray.DataArray (space: 3)>
> array([nan, nan, nan])
> Coordinates:
> * space (space) float64 0.1 0.2 0.3
> time float64 3.5
Anything else we need to know?:
I've made a pull-request to fix the issue
Environment:
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-957.27.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: None.None
xarray: 0.10.7
pandas: 0.23.0
numpy: 1.14.3
scipy: 1.1.0
netCDF4: None
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.5
distributed: 1.21.8
matplotlib: None
cartopy: None
seaborn: None
setuptools: 39.1.0
pip: 10.0.1
conda: 4.6.4
pytest: 3.5.1
IPython: 5.7.0
sphinx: 1.7.4