Skip to content

Commit 514db3a

Browse files
committed
also check use_bottleneck in ffill and bfill
1 parent 83ff0bb commit 514db3a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

xarray/core/missing.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .common import _contains_datetime_like_objects, ones_like
1313
from .computation import apply_ufunc
1414
from .duck_array_ops import datetime_to_numeric, push, timedelta_to_numeric
15-
from .options import _get_keep_attrs
15+
from .options import OPTIONS, _get_keep_attrs
1616
from .pycompat import dask_version, is_duck_dask_array
1717
from .utils import OrderedSet, is_scalar
1818
from .variable import Variable, broadcast_variables
@@ -405,6 +405,9 @@ def _bfill(arr, n=None, axis=-1):
405405

406406
def ffill(arr, dim=None, limit=None):
407407
"""forward fill missing values"""
408+
if not OPTIONS["use_bottleneck"]:
409+
raise RuntimeError("ffill requires bottleneck to be enabled")
410+
408411
axis = arr.get_axis_num(dim)
409412

410413
# work around for bottleneck 178
@@ -422,6 +425,9 @@ def ffill(arr, dim=None, limit=None):
422425

423426
def bfill(arr, dim=None, limit=None):
424427
"""backfill missing values"""
428+
if not OPTIONS["use_bottleneck"]:
429+
raise RuntimeError("bfill requires bottleneck to be enabled")
430+
425431
axis = arr.get_axis_num(dim)
426432

427433
# work around for bottleneck 178

xarray/tests/test_missing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,30 @@ def test_ffill():
392392
assert_equal(actual, expected)
393393

394394

395+
def test_ffill_use_bottleneck():
396+
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
397+
with xr.set_options(use_bottleneck=False):
398+
with pytest.raises(RuntimeError):
399+
da.ffill("x")
400+
401+
da = da.chunk({"x": 1})
402+
with xr.set_options(use_bottleneck=False):
403+
with pytest.raises(RuntimeError):
404+
da.ffill("x")
405+
406+
407+
def test_bfill_use_bottleneck():
408+
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
409+
with xr.set_options(use_bottleneck=False):
410+
with pytest.raises(RuntimeError):
411+
da.bfill("x")
412+
413+
da = da.chunk({"x": 1})
414+
with xr.set_options(use_bottleneck=False):
415+
with pytest.raises(RuntimeError):
416+
da.bfill("x")
417+
418+
395419
@requires_bottleneck
396420
@requires_dask
397421
@pytest.mark.parametrize("method", ["ffill", "bfill"])

0 commit comments

Comments
 (0)