Skip to content
Merged
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ New Features
- Allow removal of the coordinate attribute ``coordinates`` on variables by setting ``.attrs['coordinates']= None``
(:issue:`5510`).
By `Elle Smith <https://github.com/ellesmith88>`_.
- Add a option to disable the use of ``bottleneck`` (:pull:`5560`)
By `Justus Magin <https://github.com/keewis>`_.

Breaking changes
~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions xarray/core/nputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pandas as pd
from numpy.core.multiarray import normalize_axis_index # type: ignore[attr-defined]

from .options import OPTIONS

try:
import bottleneck as bn

Expand Down Expand Up @@ -138,6 +140,7 @@ def f(values, axis=None, **kwargs):

if (
_USE_BOTTLENECK
and OPTIONS["use_bottleneck"]
and isinstance(values, np.ndarray)
and bn_func is not None
and not isinstance(axis, tuple)
Expand Down
6 changes: 6 additions & 0 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
FILE_CACHE_MAXSIZE = "file_cache_maxsize"
KEEP_ATTRS = "keep_attrs"
WARN_FOR_UNCLOSED_FILES = "warn_for_unclosed_files"
USE_BOTTLENECK = "use_bottleneck"


OPTIONS = {
Expand All @@ -31,6 +32,7 @@
FILE_CACHE_MAXSIZE: 128,
KEEP_ATTRS: "default",
WARN_FOR_UNCLOSED_FILES: False,
USE_BOTTLENECK: True,
}

_JOIN_OPTIONS = frozenset(["inner", "outer", "left", "right", "exact"])
Expand All @@ -54,6 +56,7 @@ def _positive_integer(value):
FILE_CACHE_MAXSIZE: _positive_integer,
KEEP_ATTRS: lambda choice: choice in [True, False, "default"],
WARN_FOR_UNCLOSED_FILES: lambda value: isinstance(value, bool),
USE_BOTTLENECK: lambda choice: choice in [True, False],
}


Expand Down Expand Up @@ -122,6 +125,9 @@ class set_options:
attrs, ``False`` to always discard them, or ``'default'`` to use original
logic that attrs should only be kept in unambiguous circumstances.
Default: ``'default'``.
- ``use_bottleneck``: allow using bottleneck. Either ``True`` to accelerate
operations using bottleneck if it is installed or ``False`` to never use it.
Default: ``True``
- ``display_style``: display style to use in jupyter for xarray objects.
Default: ``'html'``. Other options are ``'text'``.
- ``display_expand_attrs``: whether to expand the attributes section for
Expand Down
5 changes: 3 additions & 2 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from . import dtypes, duck_array_ops, utils
from .arithmetic import CoarsenArithmetic
from .options import _get_keep_attrs
from .options import OPTIONS, _get_keep_attrs
from .pycompat import is_duck_dask_array
from .utils import either_dict_or_kwargs

Expand Down Expand Up @@ -535,7 +535,8 @@ def _numpy_or_bottleneck_reduce(
del kwargs["dim"]

if (
bottleneck_move_func is not None
OPTIONS["use_bottleneck"]
and bottleneck_move_func is not None
and not is_duck_dask_array(self.obj.data)
and len(self.dim) == 1
):
Expand Down