Skip to content

Commit

Permalink
add the context object to the reduce methods
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Aug 3, 2021
1 parent 7d3e333 commit 8fedd84
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,8 @@ def reduce(
Array with summarized data and the indicated dimension(s)
removed.
"""
from .merge import Context, merge_attrs

if dim == ...:
dim = None
if dim is not None and axis is not None:
Expand Down Expand Up @@ -1782,7 +1784,13 @@ def reduce(

if keep_attrs is None:
keep_attrs = _get_keep_attrs(default=False)
attrs = self._attrs if keep_attrs else None

if isinstance(keep_attrs, bool):
keep_attrs = "override" if keep_attrs else "drop"

attrs = merge_attrs(
[self._attrs], combine_attrs=keep_attrs, context=Context(func.__name__)
)

return Variable(dims, data, attrs=attrs)

Expand Down

0 comments on commit 8fedd84

Please sign in to comment.