Skip to content

bounds_error=True ignored in 1D interpolation #4854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leifdenby opened this issue Feb 1, 2021 · 0 comments · Fixed by #4855
Closed

bounds_error=True ignored in 1D interpolation #4854

leifdenby opened this issue Feb 1, 2021 · 0 comments · Fixed by #4855

Comments

@leifdenby
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant