Skip to content

Fix bounds_error=True ignored with 1D interpolation #4855

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

Merged
merged 6 commits into from
Feb 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions xarray/tests/test_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,20 @@ def test_interpolate_chunk_advanced(method):
z = z.chunk(3)
actual = da.interp(t=0.5, x=x, y=y, z=z, kwargs=kwargs, method=method)
assert_identical(actual, expected)


@requires_scipy
@pytest.mark.parametrize("bounds_error", [True, False])
def test_interp1d_bounds_error(bounds_error):
"""Ensure exception on bounds error is raised if requested"""
da = xr.DataArray(
np.sin(0.3 * np.arange(4)),
[("time", np.arange(4))],
)

if bounds_error:
with pytest.raises(ValueError):
da.interp(time=3.5, kwargs=dict(bounds_error=bounds_error))
else:
# default is to fill with nans, so this should pass
da.interp(time=3.5, kwargs=dict(bounds_error=bounds_error))