Skip to content

Commit 76e9ed8

Browse files
Ray Bellshoyer
Ray Bell
authored andcommitted
DOC: added sortby example (#1794)
1 parent a0ef2b7 commit 76e9ed8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

xarray/core/dataarray.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,24 @@ def sortby(self, variables, ascending=True):
19221922
sorted: DataArray
19231923
A new dataarray where all the specified dims are sorted by dim
19241924
labels.
1925+
1926+
Examples
1927+
--------
1928+
1929+
>>> da = xr.DataArray(np.random.rand(5),
1930+
... coords=[pd.date_range('1/1/2000', periods=5)],
1931+
... dims='time')
1932+
>>> da
1933+
<xarray.DataArray (time: 5)>
1934+
array([ 0.965471, 0.615637, 0.26532 , 0.270962, 0.552878])
1935+
Coordinates:
1936+
* time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 ...
1937+
1938+
>>> da.sortby(da)
1939+
<xarray.DataArray (time: 5)>
1940+
array([ 0.26532 , 0.270962, 0.552878, 0.615637, 0.965471])
1941+
Coordinates:
1942+
* time (time) datetime64[ns] 2000-01-03 2000-01-04 2000-01-05 ...
19251943
"""
19261944
ds = self._to_temp_dataset().sortby(variables, ascending=ascending)
19271945
return self._from_temp_dataset(ds)

0 commit comments

Comments
 (0)