From 9cead146943db82435b0910eb3a7815af34f6cc3 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 5 Mar 2020 22:30:20 -0500 Subject: [PATCH 1/4] improve the where docstring --- xarray/core/computation.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index d2c5c32bc00..c55803bf33a 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1225,14 +1225,18 @@ def where(cond, x, y): ---------- cond : scalar, array, Variable, DataArray or Dataset with boolean dtype When True, return values from `x`, otherwise returns values from `y`. - x, y : scalar, array, Variable, DataArray or Dataset - Values from which to choose. All dimension coordinates on these objects - must be aligned with each other and with `cond`. + x : scalar, array, Variable, DataArray or Dataset + values to choose from where `cond` is True + y : scalar, array, Variable, DataArray or Dataset + values to choose from where `cond` is False + + All dimension coordinates on these objects must be aligned with each + other and with `cond`. Returns ------- - In priority order: Dataset, DataArray, Variable or array, whichever - type appears as an input argument. + Dataset, DataArray, Variable or array, whichever type appears as an input + argument. Examples -------- @@ -1246,13 +1250,13 @@ def where(cond, x, y): Coordinates: * lat (lat) int64 0 1 2 3 4 5 6 7 8 9 - >>> xr.where(x < 0.5, x, 100*x) + >>> xr.where(x < 0.5, x, x * 100) array([ 0. , 0.1, 0.2, 0.3, 0.4, 50. , 60. , 70. , 80. , 90. ]) Coordinates: * lat (lat) int64 0 1 2 3 4 5 6 7 8 9 - >>> >>> y = xr.DataArray( + >>> y = xr.DataArray( ... 0.1 * np.arange(9).reshape(3, 3), ... dims=["lat", "lon"], ... coords={"lat": np.arange(3), "lon": 10 + np.arange(3)}, From e1627042caea636d4cd2396726966d6377bd55f8 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 5 Mar 2020 22:39:56 -0500 Subject: [PATCH 2/4] whatsnew --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 4a6083522ba..3ba23d1e1e5 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -74,6 +74,8 @@ Documentation - Fix documentation of :py:class:`DataArray` removing the deprecated mention that when omitted, `dims` are inferred from a `coords`-dict. (:pull:`3821`) By `Sander van Rijn `_. +- Improve the :py:func:`where` docstring. + By `Maximilian Roos `_ Internal Changes ~~~~~~~~~~~~~~~~ From c0bcd1f13da7c28f7831d1e5dd3ce619be5d2599 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 5 Mar 2020 23:29:25 -0500 Subject: [PATCH 3/4] improve assign docstring --- xarray/core/dataset.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 7252dd2f3df..a1edb4d3d8c 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -4362,8 +4362,6 @@ def assign( Examples -------- - >>> import numpy as np - >>> import xarray as xr >>> x = xr.Dataset( ... { ... "temperature_c": (("lat", "lon"), 20 * np.random.rand(4).reshape(2, 2)), @@ -4383,7 +4381,7 @@ def assign( Where the value is a callable, evaluated on dataset: - >>> x.assign(temperature_f = lambda x: x.temperature_c * 9 / 5 + 32) + >>> x.assign(temperature_f=lambda x: x.temperature_c * 9 / 5 + 32) Dimensions: (lat: 2, lon: 2) Coordinates: From 7bbd7a6bc5405157d0882e33413a857289752ef1 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 19 Mar 2020 15:29:16 -0400 Subject: [PATCH 4/4] changes from @dcherian --- xarray/core/computation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index cf992bc7ec6..f2941a3d0ba 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1234,8 +1234,8 @@ def where(cond, x, y): Returns ------- - Dataset, DataArray, Variable or array, whichever type appears as an input - argument. + In priority order: Dataset, DataArray, Variable or array, whichever + type appears as an input argument. Examples --------