From 0daf42dd0267025b58d11670bf7c75a3482d2b74 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sat, 6 Feb 2021 00:03:26 +0100 Subject: [PATCH] add examples [skip-ci] --- xarray/core/computation.py | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 98883fcd6b5..08c55a1a775 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1170,6 +1170,49 @@ def apply_to_dataset(func, obj, *args, **kwargs): Dataset.map Dataset.pipe DataArray.pipe + + Examples + -------- + >>> def f(ds): + ... return xr.Dataset( + ... { + ... name: var * var.attrs.get("scale", 1) + ... for name, var in ds.data_vars.items() + ... }, + ... coords=ds.coords, + ... attrs=ds.attrs, + ... ) + ... + >>> ds = xr.Dataset( + ... {"a": ("x", [3, 4], {"scale": 0.5}), "b": ("x", [-1, 1], {"scale": 1.5})}, + ... coords={"x": [0, 1]}, + ... attrs={"attr": "value"}, + ... ) + >>> ds + + Dimensions: (x: 2) + Coordinates: + * x (x) int64 0 1 + Data variables: + a (x) int64 3 4 + b (x) int64 -1 1 + Attributes: + attr: value + >>> xr.apply_to_dataset(f, ds) + + Dimensions: (x: 2) + Coordinates: + * x (x) int64 0 1 + Data variables: + a (x) float64 1.5 2.0 + b (x) float64 -1.5 1.5 + Attributes: + attr: value + >>> xr.apply_to_dataset(f, ds.a) + + array([1.5, 2. ]) + Coordinates: + * x (x) int64 0 1 """ from .dataarray import DataArray