Skip to content

Commit 5548c1e

Browse files
authored
Improve where docstring (#3836)
* improve the where docstring * whatsnew * improve assign docstring * changes from @dcherian
1 parent e7d6e12 commit 5548c1e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Documentation
9494
- Fix documentation of :py:class:`DataArray` removing the deprecated mention
9595
that when omitted, `dims` are inferred from a `coords`-dict. (:pull:`3821`)
9696
By `Sander van Rijn <https://github.com/sjvrijn>`_.
97+
- Improve the :py:func:`where` docstring.
98+
By `Maximilian Roos <https://github.com/max-sixty>`_
9799
- Update the installation instructions: only explicitly list recommended dependencies
98100
(:issue:`3756`).
99101
By `Mathias Hauser <https://github.com/mathause>`_.

xarray/core/computation.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,9 +1224,13 @@ def where(cond, x, y):
12241224
----------
12251225
cond : scalar, array, Variable, DataArray or Dataset with boolean dtype
12261226
When True, return values from `x`, otherwise returns values from `y`.
1227-
x, y : scalar, array, Variable, DataArray or Dataset
1228-
Values from which to choose. All dimension coordinates on these objects
1229-
must be aligned with each other and with `cond`.
1227+
x : scalar, array, Variable, DataArray or Dataset
1228+
values to choose from where `cond` is True
1229+
y : scalar, array, Variable, DataArray or Dataset
1230+
values to choose from where `cond` is False
1231+
1232+
All dimension coordinates on these objects must be aligned with each
1233+
other and with `cond`.
12301234
12311235
Returns
12321236
-------
@@ -1249,7 +1253,7 @@ def where(cond, x, y):
12491253
Coordinates:
12501254
* lat (lat) int64 0 1 2 3 4 5 6 7 8 9
12511255
1252-
>>> xr.where(x < 0.5, x, 100 * x)
1256+
>>> xr.where(x < 0.5, x, x * 100)
12531257
<xarray.DataArray 'sst' (lat: 10)>
12541258
array([ 0. , 0.1, 0.2, 0.3, 0.4, 50. , 60. , 70. , 80. , 90. ])
12551259
Coordinates:

xarray/core/dataset.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,8 +4392,6 @@ def assign(
43924392
43934393
Examples
43944394
--------
4395-
>>> import numpy as np
4396-
>>> import xarray as xr
43974395
>>> x = xr.Dataset(
43984396
... {
43994397
... "temperature_c": (

0 commit comments

Comments
 (0)