Skip to content

Commit

Permalink
Add examples to docstrings (#7937)
Browse files Browse the repository at this point in the history
* xarray.dataset.equals

* xarray.dataset.identical

* xarray.dataset.broadcast_equals

* minute_change

* assign_attrs

* expand_dims

* drop_vars

* equals

* broadcast.equals

* identical

* indentation

* .

* .

* indentation

* .

* what's new

* .

* .

* .

* .

* .

* .

* Try adding Traceback to doctest which raises error

* changing it intlo sub-heading

* what's new added

* indentation error fixed

* doctest

* Make possible raising of ValueError in drop_vars general

---------

Co-authored-by: Tom Nicholas <[email protected]>
  • Loading branch information
harshitha1201 and TomNicholas authored Jul 25, 2023
1 parent 88315fd commit bb501ba
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ See the `Installation <https://docs.xarray.dev/en/stable/getting-started-guide/i
See the `Quick Overview <https://docs.xarray.dev/en/stable/getting-started-guide/quick-overview.html>`_

Including figures and files
---------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Image files can be directly included in pages with the ``image::`` directive.

Expand Down
9 changes: 6 additions & 3 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Bug fixes
Documentation
~~~~~~~~~~~~~

- Added examples to docstrings of :py:meth:`Dataset.assign_attrs`, :py:meth:`Dataset.broadcast_equals`,
:py:meth:`Dataset.equals`, :py:meth:`Dataset.identical`, :py:meth:`Dataset.expand_dims`,:py:meth:`Dataset.drop_vars`
(:issue:`6793`, :pull:`7937`) By `Harshitha <https://github.com/harshitha1201>`_.
- Add docstrings for the :py:class:`Index` base class and add some documentation on how to
create custom, Xarray-compatible indexes (:pull:`6975`)
By `Benoît Bovy <https://github.com/benbovy>`_.
Expand Down Expand Up @@ -93,9 +96,9 @@ Bug fixes
Documentation
~~~~~~~~~~~~~

- Added examples to docstrings of :py:meth:`Dataset.tail`, :py:meth:`Dataset.head`, :py:meth:`Dataset.dropna`,
:py:meth:`Dataset.ffill`, :py:meth:`Dataset.bfill`, :py:meth:`Dataset.set_coords`, :py:meth:`Dataset.reset_coords`
(:issue:`6793`, :pull:`7936`) By `Harshitha <https://github.com/harshitha1201>`_ .
- Added examples to docstrings of :py:meth:`Dataset.assign_attrs`, :py:meth:`Dataset.broadcast_equals`,
:py:meth:`Dataset.equals`, :py:meth:`Dataset.identical`, :py:meth:`Dataset.expand_dims`,:py:meth:`Dataset.drop_vars`
(:issue:`6793`, :pull:`7937`) By `Harshitha <https://github.com/harshitha1201>`_.
- Added page on wrapping chunked numpy-like arrays as alternatives to dask arrays.
(:pull:`7951`) By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Expanded the page on wrapping numpy-like "duck" arrays.
Expand Down
30 changes: 30 additions & 0 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,36 @@ def assign_attrs(
**kwargs
keyword arguments passed into ``attrs.update``.
Examples
--------
>>> dataset = xr.Dataset({"temperature": [25, 30, 27]})
>>> dataset
<xarray.Dataset>
Dimensions: (temperature: 3)
Coordinates:
* temperature (temperature) int64 25 30 27
Data variables:
*empty*
>>> new_dataset = dataset.assign_attrs(
... units="Celsius", description="Temperature data"
... )
>>> new_dataset
<xarray.Dataset>
Dimensions: (temperature: 3)
Coordinates:
* temperature (temperature) int64 25 30 27
Data variables:
*empty*
Attributes:
units: Celsius
description: Temperature data
# Attributes of the new dataset
>>> new_dataset.attrs
{'units': 'Celsius', 'description': 'Temperature data'}
Returns
-------
assigned : same type as caller
Expand Down
Loading

0 comments on commit bb501ba

Please sign in to comment.