Skip to content

Commit

Permalink
Deprecate allow_lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Oct 22, 2019
1 parent 72be873 commit 638a9a8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
17 changes: 4 additions & 13 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ def _reduce_method(cls, func: Callable, include_skipna: bool, numeric_only: bool
if include_skipna:

def wrapped_func(self, dim=None, axis=None, skipna=None, **kwargs):
return self.reduce(
func, dim, axis, skipna=skipna, allow_lazy=True, **kwargs
)
return self.reduce(func, dim, axis, skipna=skipna, **kwargs)

else:

def wrapped_func(self, dim=None, axis=None, **kwargs): # type: ignore
return self.reduce(func, dim, axis, allow_lazy=True, **kwargs)
return self.reduce(func, dim, axis, **kwargs)

return wrapped_func

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

def wrapped_func(self, dim=None, skipna=None, **kwargs):
return self.reduce(
func,
dim,
skipna=skipna,
numeric_only=numeric_only,
allow_lazy=True,
**kwargs,
func, dim, skipna=skipna, numeric_only=numeric_only, **kwargs
)

else:

def wrapped_func(self, dim=None, **kwargs): # type: ignore
return self.reduce(
func, dim, numeric_only=numeric_only, allow_lazy=True, **kwargs
)
return self.reduce(func, dim, numeric_only=numeric_only, **kwargs)

return wrapped_func

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3999,7 +3999,7 @@ def reduce(
keep_attrs: bool = None,
keepdims: bool = False,
numeric_only: bool = False,
allow_lazy: bool = False,
allow_lazy: bool = None,
**kwargs: Any,
) -> "Dataset":
"""Reduce this dataset by applying `func` along some dimension(s).
Expand Down
4 changes: 1 addition & 3 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,7 @@ def _first_or_last(self, op, skipna, keep_attrs):
return self._obj
if keep_attrs is None:
keep_attrs = _get_keep_attrs(default=True)
return self.reduce(
op, self._group_dim, skipna=skipna, keep_attrs=keep_attrs, allow_lazy=True
)
return self.reduce(op, self._group_dim, skipna=skipna, keep_attrs=keep_attrs)

def first(self, skipna=None, keep_attrs=None):
"""Return the first element of each group along the group dimension
Expand Down
13 changes: 12 additions & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import itertools
import warnings
from collections import defaultdict
from datetime import timedelta
from distutils.version import LooseVersion
Expand Down Expand Up @@ -1416,7 +1417,7 @@ def reduce(
axis=None,
keep_attrs=None,
keepdims=False,
allow_lazy=False,
allow_lazy=None,
**kwargs,
):
"""Reduce this array by applying `func` along some dimension(s).
Expand Down Expand Up @@ -1457,7 +1458,17 @@ def reduce(

if dim is not None:
axis = self.get_axis_num(dim)

if allow_lazy is not None:
warnings.warn(
"allow_lazy will be deprecated in version 0.16.0. It is now True by default.",
DeprecationWarning,
)
else:
allow_lazy = True

input_data = self.data if allow_lazy else self.values

if axis is not None:
data = func(input_data, axis=axis, **kwargs)
else:
Expand Down
4 changes: 4 additions & 0 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@ def test_reduce(self):

with raises_regex(ValueError, "cannot supply both"):
v.mean(dim="x", axis=0)
with pytest.warns(DeprecationWarning, match="allow_lazy will be deprecated"):
v.mean("x", allow_lazy=True)
with pytest.warns(DeprecationWarning, match="allow_lazy will be deprecated"):
v.mean("x", allow_lazy=False)

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

0 comments on commit 638a9a8

Please sign in to comment.