Skip to content

Commit 008a99c

Browse files
takluyverkeewis
andauthored
Disable bottleneck by default (#11461)
* Disable bottleneck by default * Document disabling bottleneck * Ignore use_bottleneck option for rank() method * Re-enable bottleneck for rolling tests * Add name to release note Co-authored-by: Justus Magin <keewis@users.noreply.github.com> * move to breaking changes [skip-ci] (since technically this is changing the trade-off between speed and accuracy) --------- Co-authored-by: Justus Magin <keewis@users.noreply.github.com> Co-authored-by: Justus Magin <keewis@posteo.de>
1 parent adc8005 commit 008a99c

7 files changed

Lines changed: 10 additions & 25 deletions

File tree

doc/whats-new.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ New Features
1717

1818
Breaking Changes
1919
~~~~~~~~~~~~~~~~
20-
20+
- Disable using bottleneck by default, as certain operations are less numerically
21+
stable than the equivalent numpy functions.
22+
By `Thomas Kluyver <https://github.com/takluyver>`_.
2123

2224
Deprecations
2325
~~~~~~~~~~~~

xarray/core/dataset.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
is_duck_dask_array,
101101
is_scalar,
102102
maybe_wrap_array,
103+
module_available,
103104
parse_dims_as_set,
104105
)
105106
from xarray.core.variable import (
@@ -8447,11 +8448,8 @@ def rank(
84478448
ranked : Dataset
84488449
Variables that do not depend on `dim` are dropped.
84498450
"""
8450-
if not OPTIONS["use_bottleneck"]:
8451-
raise RuntimeError(
8452-
"rank requires bottleneck to be enabled."
8453-
" Call `xr.set_options(use_bottleneck=True)` to enable it."
8454-
)
8451+
if not module_available("bottleneck"):
8452+
raise ImportError("rank requires bottleneck to be installed.")
84558453

84568454
if dim not in self.dims:
84578455
raise ValueError(

xarray/core/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class T_Options(TypedDict):
103103
"keep_attrs": "default",
104104
"netcdf_engine_order": ("netcdf4", "h5netcdf", "scipy"),
105105
"warn_for_unclosed_files": False,
106-
"use_bottleneck": True,
106+
"use_bottleneck": False,
107107
"use_flox": True,
108108
"use_new_combine_kwarg_defaults": False,
109109
"use_numbagg": True,

xarray/core/variable.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,11 +2093,8 @@ def rank(self, dim, pct=False):
20932093
Dataset.rank, DataArray.rank
20942094
"""
20952095
# This could / should arguably be implemented at the DataArray & Dataset level
2096-
if not OPTIONS["use_bottleneck"]:
2097-
raise RuntimeError(
2098-
"rank requires bottleneck to be enabled."
2099-
" Call `xr.set_options(use_bottleneck=True)` to enable it."
2100-
)
2096+
if not module_available("bottleneck"):
2097+
raise ImportError("rank requires bottleneck to be installed.")
21012098

21022099
import bottleneck as bn
21032100

xarray/tests/test_dataset.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6518,12 +6518,6 @@ def test_rank(self) -> None:
65186518
):
65196519
x.rank("invalid_dim")
65206520

6521-
def test_rank_use_bottleneck(self) -> None:
6522-
ds = Dataset({"a": ("x", [0, np.nan, 2]), "b": ("y", [4, 6, 3, 4])})
6523-
with xr.set_options(use_bottleneck=False):
6524-
with pytest.raises(RuntimeError):
6525-
ds.rank("x")
6526-
65276521
def test_count(self) -> None:
65286522
ds = Dataset({"x": ("a", [np.nan, 1]), "y": 0, "z": np.nan})
65296523
expected = Dataset({"x": 1, "y": 1, "z": 0})

xarray/tests/test_rolling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test_rolling_bottleneck_dask_dtype_matches_numpy(
460460
.rolling(t=72, min_periods=72, center=center)
461461
)
462462

463-
with set_options(use_numbagg=False):
463+
with set_options(use_numbagg=False, use_bottleneck=True):
464464
expected = getattr(unchunked, name)()
465465
actual = getattr(chunked, name)()
466466
actual_block = actual.data.blocks[0, 0].compute()

xarray/tests/test_variable.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,12 +2018,6 @@ def test_rank_dask(self):
20182018
):
20192019
v.rank("x")
20202020

2021-
def test_rank_use_bottleneck(self):
2022-
v = Variable(["x"], [3.0, 1.0, np.nan, 2.0, 4.0])
2023-
with set_options(use_bottleneck=False):
2024-
with pytest.raises(RuntimeError):
2025-
v.rank("x")
2026-
20272021
@requires_bottleneck
20282022
def test_rank(self):
20292023
import bottleneck as bn

0 commit comments

Comments
 (0)