Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Bug fixes
:py:meth:`Dataset.to_zarr` (:issue:`4783`, :pull:`4795`).
By `Julien Seguinot <https://github.com/juseg>`_.
- Add :py:meth:`Dataset.drop_isel` and :py:meth:`DataArray.drop_isel` (:issue:`4658`, :pull:`4819`). By `Daniel Mesejo <https://github.com/mesejo>`_.
- Ensure that `Dataset.interp` raises `ValueError` when interpolating outside coordinate range and `bounds_error=True` (:issue:`4854`, :pull:`4855`). By `Leif Denby <https://github.com/leifdenby>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(
yi,
kind=self.method,
fill_value=fill_value,
bounds_error=False,
bounds_error=bounds_error,
assume_sorted=assume_sorted,
copy=copy,
**self.cons_kwargs,
Expand Down
15 changes: 15 additions & 0 deletions xarray/tests/test_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,18 @@ 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
def test_interp1d_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))],
)

with pytest.raises(ValueError):
da.interp(time=3.5, kwargs=dict(bounds_error=True))

# default is to fill with nans, so this should pass
da.interp(time=3.5)