|
10 | 10 | import numpy as np
|
11 | 11 | from packaging.version import Version
|
12 | 12 |
|
13 |
| -from xarray.core import dtypes, duck_array_ops, utils |
| 13 | +from xarray.core import dask_array_ops, dtypes, duck_array_ops, utils |
14 | 14 | from xarray.core.arithmetic import CoarsenArithmetic
|
15 | 15 | from xarray.core.options import OPTIONS, _get_keep_attrs
|
16 | 16 | from xarray.core.types import CoarsenBoundaryOptions, SideOptions, T_Xarray
|
@@ -597,16 +597,18 @@ def _bottleneck_reduce(self, func, keep_attrs, **kwargs):
|
597 | 597 | padded = padded.pad({self.dim[0]: (0, -shift)}, mode="constant")
|
598 | 598 |
|
599 | 599 | if is_duck_dask_array(padded.data):
|
600 |
| - raise AssertionError("should not be reachable") |
| 600 | + values = dask_array_ops.dask_rolling_wrapper( |
| 601 | + func, padded, axis=axis, window=self.window[0], min_count=min_count |
| 602 | + ) |
601 | 603 | else:
|
602 | 604 | values = func(
|
603 | 605 | padded.data, window=self.window[0], min_count=min_count, axis=axis
|
604 | 606 | )
|
605 |
| - # index 0 is at the rightmost edge of the window |
606 |
| - # need to reverse index here |
607 |
| - # see GH #8541 |
608 |
| - if func in [bottleneck.move_argmin, bottleneck.move_argmax]: |
609 |
| - values = self.window[0] - 1 - values |
| 607 | + # index 0 is at the rightmost edge of the window |
| 608 | + # need to reverse index here |
| 609 | + # see GH #8541 |
| 610 | + if func in [bottleneck.move_argmin, bottleneck.move_argmax]: |
| 611 | + values = self.window[0] - 1 - values |
610 | 612 |
|
611 | 613 | if self.center[0]:
|
612 | 614 | values = values[valid]
|
@@ -669,12 +671,12 @@ def _array_reduce(
|
669 | 671 | if (
|
670 | 672 | OPTIONS["use_bottleneck"]
|
671 | 673 | and bottleneck_move_func is not None
|
672 |
| - and not is_duck_dask_array(self.obj.data) |
| 674 | + and ( |
| 675 | + not is_duck_dask_array(self.obj.data) |
| 676 | + or module_available("dask", "2024.11.0") |
| 677 | + ) |
673 | 678 | and self.ndim == 1
|
674 | 679 | ):
|
675 |
| - # TODO: re-enable bottleneck with dask after the issues |
676 |
| - # underlying https://github.com/pydata/xarray/issues/2940 are |
677 |
| - # fixed. |
678 | 680 | return self._bottleneck_reduce(
|
679 | 681 | bottleneck_move_func, keep_attrs=keep_attrs, **kwargs
|
680 | 682 | )
|
|
0 commit comments