Skip to content

Commit

Permalink
DOC: sortby see also (#5797)
Browse files Browse the repository at this point in the history
* DOC: sortby see also

* more see alsos

* add to howdoi

* lint

* rm }

* rm space

* spacing

Co-authored-by: Ray Bell <ray.bell@dtn.com>
  • Loading branch information
raybellwaves and Ray Bell authored Sep 15, 2021
1 parent f3237bc commit 06a83ef
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/howdoi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ How do I ...
- :py:attr:`DataArray.data`
* - convert to and extract the underlying NumPy array
- :py:attr:`DataArray.values`
* - convert to a pandas DataFrame
- :py:attr:`Dataset.to_dataframe`
* - sort values
- :py:attr:`Dataset.sortby`
* - find out if my xarray object is wrapping a Dask Array
- :py:func:`dask.is_dask_collection`
* - know how much memory my object requires
Expand Down
5 changes: 4 additions & 1 deletion doc/user-guide/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ One may sort a DataArray/Dataset via :py:meth:`~xarray.DataArray.sortby` and
.. ipython:: python
ds = xr.Dataset(
{"A": (("x", "y"), [[1, 2], [3, 4]]), "B": (("x", "y"), [[5, 6], [7, 8]])},
{
"A": (("x", "y"), [[1, 2], [3, 4]]),
"B": (("x", "y"), [[5, 6], [7, 8]]),
},
coords={"x": ["b", "a"], "y": [1, 0]},
)
dax = xr.DataArray([100, 99], [("x", [0, 1])])
Expand Down
11 changes: 9 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def to_numpy(self) -> np.ndarray:
"""
Coerces wrapped data to numpy and returns a numpy.ndarray.
See also
See Also
--------
DataArray.as_numpy : Same but returns the surrounding DataArray instead.
Dataset.as_numpy
Expand All @@ -665,7 +665,7 @@ def as_numpy(self: T_DataArray) -> T_DataArray:
"""
Coerces wrapped data and coordinates into numpy arrays, returning a DataArray.
See also
See Also
--------
DataArray.to_numpy : Same but returns only the data as a numpy.ndarray object.
Dataset.as_numpy : Converts all variables in a Dataset.
Expand Down Expand Up @@ -3354,6 +3354,13 @@ def sortby(
A new dataarray where all the specified dims are sorted by dim
labels.
See Also
--------
Dataset.sortby
numpy.sort
pandas.sort_values
pandas.sort_index
Examples
--------
>>> da = xr.DataArray(
Expand Down
26 changes: 26 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6036,6 +6036,32 @@ def sortby(self, variables, ascending=True):
sorted : Dataset
A new dataset where all the specified dims are sorted by dim
labels.
See Also
--------
DataArray.sortby
numpy.sort
pandas.sort_values
pandas.sort_index
Examples
--------
>>> ds = xr.Dataset(
... {
... "A": (("x", "y"), [[1, 2], [3, 4]]),
... "B": (("x", "y"), [[5, 6], [7, 8]]),
... },
... coords={"x": ["b", "a"], "y": [1, 0]},
... )
>>> ds.sortby("x")
<xarray.Dataset>
Dimensions: (x: 2, y: 2)
Coordinates:
* x (x) <U1 'a' 'b'
* y (y) int64 1 0
Data variables:
A (x, y) int64 3 4 1 2
B (x, y) int64 7 8 5 6
"""
from .dataarray import DataArray

Expand Down

0 comments on commit 06a83ef

Please sign in to comment.