Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ New Features

Breaking Changes
~~~~~~~~~~~~~~~~

- Disable using bottleneck by default, as certain operations are less numerically
stable than the equivalent numpy functions.
By `Thomas Kluyver <https://github.com/takluyver>`_.

Deprecations
~~~~~~~~~~~~
Expand Down
8 changes: 3 additions & 5 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
is_duck_dask_array,
is_scalar,
maybe_wrap_array,
module_available,
parse_dims_as_set,
)
from xarray.core.variable import (
Expand Down Expand Up @@ -8447,11 +8448,8 @@ def rank(
ranked : Dataset
Variables that do not depend on `dim` are dropped.
"""
if not OPTIONS["use_bottleneck"]:
raise RuntimeError(
"rank requires bottleneck to be enabled."
" Call `xr.set_options(use_bottleneck=True)` to enable it."
)
if not module_available("bottleneck"):
raise ImportError("rank requires bottleneck to be installed.")

if dim not in self.dims:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class T_Options(TypedDict):
"keep_attrs": "default",
"netcdf_engine_order": ("netcdf4", "h5netcdf", "scipy"),
"warn_for_unclosed_files": False,
"use_bottleneck": True,
"use_bottleneck": False,
"use_flox": True,
"use_new_combine_kwarg_defaults": False,
"use_numbagg": True,
Expand Down
7 changes: 2 additions & 5 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,11 +2093,8 @@ def rank(self, dim, pct=False):
Dataset.rank, DataArray.rank
"""
# This could / should arguably be implemented at the DataArray & Dataset level
if not OPTIONS["use_bottleneck"]:
raise RuntimeError(
"rank requires bottleneck to be enabled."
" Call `xr.set_options(use_bottleneck=True)` to enable it."
)
if not module_available("bottleneck"):
raise ImportError("rank requires bottleneck to be installed.")

import bottleneck as bn

Expand Down
6 changes: 0 additions & 6 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6518,12 +6518,6 @@ def test_rank(self) -> None:
):
x.rank("invalid_dim")

def test_rank_use_bottleneck(self) -> None:
ds = Dataset({"a": ("x", [0, np.nan, 2]), "b": ("y", [4, 6, 3, 4])})
with xr.set_options(use_bottleneck=False):
with pytest.raises(RuntimeError):
ds.rank("x")

def test_count(self) -> None:
ds = Dataset({"x": ("a", [np.nan, 1]), "y": 0, "z": np.nan})
expected = Dataset({"x": 1, "y": 1, "z": 0})
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_rolling_bottleneck_dask_dtype_matches_numpy(
.rolling(t=72, min_periods=72, center=center)
)

with set_options(use_numbagg=False):
with set_options(use_numbagg=False, use_bottleneck=True):
expected = getattr(unchunked, name)()
actual = getattr(chunked, name)()
actual_block = actual.data.blocks[0, 0].compute()
Expand Down
6 changes: 0 additions & 6 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,12 +2018,6 @@ def test_rank_dask(self):
):
v.rank("x")

def test_rank_use_bottleneck(self):
v = Variable(["x"], [3.0, 1.0, np.nan, 2.0, 4.0])
with set_options(use_bottleneck=False):
with pytest.raises(RuntimeError):
v.rank("x")

@requires_bottleneck
def test_rank(self):
import bottleneck as bn
Expand Down