Skip to content

Commit 638a9a8

Browse files
committed
Deprecate allow_lazy
1 parent 72be873 commit 638a9a8

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

xarray/core/common.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ def _reduce_method(cls, func: Callable, include_skipna: bool, numeric_only: bool
4242
if include_skipna:
4343

4444
def wrapped_func(self, dim=None, axis=None, skipna=None, **kwargs):
45-
return self.reduce(
46-
func, dim, axis, skipna=skipna, allow_lazy=True, **kwargs
47-
)
45+
return self.reduce(func, dim, axis, skipna=skipna, **kwargs)
4846

4947
else:
5048

5149
def wrapped_func(self, dim=None, axis=None, **kwargs): # type: ignore
52-
return self.reduce(func, dim, axis, allow_lazy=True, **kwargs)
50+
return self.reduce(func, dim, axis, **kwargs)
5351

5452
return wrapped_func
5553

@@ -82,20 +80,13 @@ def _reduce_method(cls, func: Callable, include_skipna: bool, numeric_only: bool
8280

8381
def wrapped_func(self, dim=None, skipna=None, **kwargs):
8482
return self.reduce(
85-
func,
86-
dim,
87-
skipna=skipna,
88-
numeric_only=numeric_only,
89-
allow_lazy=True,
90-
**kwargs,
83+
func, dim, skipna=skipna, numeric_only=numeric_only, **kwargs
9184
)
9285

9386
else:
9487

9588
def wrapped_func(self, dim=None, **kwargs): # type: ignore
96-
return self.reduce(
97-
func, dim, numeric_only=numeric_only, allow_lazy=True, **kwargs
98-
)
89+
return self.reduce(func, dim, numeric_only=numeric_only, **kwargs)
9990

10091
return wrapped_func
10192

xarray/core/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3999,7 +3999,7 @@ def reduce(
39993999
keep_attrs: bool = None,
40004000
keepdims: bool = False,
40014001
numeric_only: bool = False,
4002-
allow_lazy: bool = False,
4002+
allow_lazy: bool = None,
40034003
**kwargs: Any,
40044004
) -> "Dataset":
40054005
"""Reduce this dataset by applying `func` along some dimension(s).

xarray/core/groupby.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,7 @@ def _first_or_last(self, op, skipna, keep_attrs):
564564
return self._obj
565565
if keep_attrs is None:
566566
keep_attrs = _get_keep_attrs(default=True)
567-
return self.reduce(
568-
op, self._group_dim, skipna=skipna, keep_attrs=keep_attrs, allow_lazy=True
569-
)
567+
return self.reduce(op, self._group_dim, skipna=skipna, keep_attrs=keep_attrs)
570568

571569
def first(self, skipna=None, keep_attrs=None):
572570
"""Return the first element of each group along the group dimension

xarray/core/variable.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import itertools
3+
import warnings
34
from collections import defaultdict
45
from datetime import timedelta
56
from distutils.version import LooseVersion
@@ -1416,7 +1417,7 @@ def reduce(
14161417
axis=None,
14171418
keep_attrs=None,
14181419
keepdims=False,
1419-
allow_lazy=False,
1420+
allow_lazy=None,
14201421
**kwargs,
14211422
):
14221423
"""Reduce this array by applying `func` along some dimension(s).
@@ -1457,7 +1458,17 @@ def reduce(
14571458

14581459
if dim is not None:
14591460
axis = self.get_axis_num(dim)
1461+
1462+
if allow_lazy is not None:
1463+
warnings.warn(
1464+
"allow_lazy will be deprecated in version 0.16.0. It is now True by default.",
1465+
DeprecationWarning,
1466+
)
1467+
else:
1468+
allow_lazy = True
1469+
14601470
input_data = self.data if allow_lazy else self.values
1471+
14611472
if axis is not None:
14621473
data = func(input_data, axis=axis, **kwargs)
14631474
else:

xarray/tests/test_variable.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,10 @@ def test_reduce(self):
14741474

14751475
with raises_regex(ValueError, "cannot supply both"):
14761476
v.mean(dim="x", axis=0)
1477+
with pytest.warns(DeprecationWarning, match="allow_lazy will be deprecated"):
1478+
v.mean("x", allow_lazy=True)
1479+
with pytest.warns(DeprecationWarning, match="allow_lazy will be deprecated"):
1480+
v.mean("x", allow_lazy=False)
14771481

14781482
def test_quantile(self):
14791483
v = Variable(["x", "y"], self.d)

0 commit comments

Comments
 (0)