MCPcopy Index your code
hub / github.com/pydata/xarray / reduce

Method reduce

xarray/core/datatree.py:2221–2252  ·  view source on GitHub ↗

Reduce this tree by applying `func` along some dimension(s).

(
        self,
        func: Callable,
        dim: Dims = None,
        *,
        keep_attrs: bool | None = None,
        keepdims: bool = False,
        numeric_only: bool = False,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

2219 return all_dims
2220
2221 def reduce(
2222 self,
2223 func: Callable,
2224 dim: Dims = None,
2225 *,
2226 keep_attrs: bool | None = None,
2227 keepdims: bool = False,
2228 numeric_only: bool = False,
2229 **kwargs: Any,
2230 ) -> Self:
2231 """Reduce this tree by applying `func` along some dimension(s)."""
2232 dims = parse_dims_as_set(dim, self._get_all_dims())
2233 result = {}
2234 for path, node in self.subtree_with_keys:
2235 reduce_dims = [d for d in node._node_dims if d in dims]
2236
2237 # Prefer Dataset.func(...) over Dataset.reduce(func, ...),
2238 # because Dataset.func(...) may do further func-specific processing:
2239 f = getattr(node.dataset, func.__name__, None)
2240 if f:
2241 node_result = f(reduce_dims, keep_attrs=keep_attrs, **kwargs)
2242 else:
2243 node_result = node.dataset.reduce(
2244 func,
2245 reduce_dims,
2246 keep_attrs=keep_attrs,
2247 keepdims=keepdims,
2248 numeric_only=numeric_only,
2249 **kwargs,
2250 )
2251 result[path] = node_result
2252 return type(self).from_dict(result, name=self.name)
2253
2254 def _selective_indexing(
2255 self,

Callers

nothing calls this directly

Calls 5

_get_all_dimsMethod · 0.95
parse_dims_as_setFunction · 0.90
typeFunction · 0.85
fFunction · 0.70
from_dictMethod · 0.45

Tested by

no test coverage detected