Skip to content

Commit bb501ba

Browse files
Add examples to docstrings (#7937)
* 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 <thomas.nicholas@columbia.edu>
1 parent 88315fd commit bb501ba

File tree

4 files changed

+355
-4
lines changed

4 files changed

+355
-4
lines changed

doc/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ See the `Installation <https://docs.xarray.dev/en/stable/getting-started-guide/i
518518
See the `Quick Overview <https://docs.xarray.dev/en/stable/getting-started-guide/quick-overview.html>`_
519519

520520
Including figures and files
521-
---------------------------
521+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
522522

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

doc/whats-new.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Bug fixes
5959
Documentation
6060
~~~~~~~~~~~~~
6161

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

96-
- Added examples to docstrings of :py:meth:`Dataset.tail`, :py:meth:`Dataset.head`, :py:meth:`Dataset.dropna`,
97-
:py:meth:`Dataset.ffill`, :py:meth:`Dataset.bfill`, :py:meth:`Dataset.set_coords`, :py:meth:`Dataset.reset_coords`
98-
(:issue:`6793`, :pull:`7936`) By `Harshitha <https://github.com/harshitha1201>`_ .
99+
- Added examples to docstrings of :py:meth:`Dataset.assign_attrs`, :py:meth:`Dataset.broadcast_equals`,
100+
:py:meth:`Dataset.equals`, :py:meth:`Dataset.identical`, :py:meth:`Dataset.expand_dims`,:py:meth:`Dataset.drop_vars`
101+
(:issue:`6793`, :pull:`7937`) By `Harshitha <https://github.com/harshitha1201>`_.
99102
- Added page on wrapping chunked numpy-like arrays as alternatives to dask arrays.
100103
(:pull:`7951`) By `Tom Nicholas <https://github.com/TomNicholas>`_.
101104
- Expanded the page on wrapping numpy-like "duck" arrays.

xarray/core/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,36 @@ def assign_attrs(
634634
**kwargs
635635
keyword arguments passed into ``attrs.update``.
636636
637+
Examples
638+
--------
639+
>>> dataset = xr.Dataset({"temperature": [25, 30, 27]})
640+
>>> dataset
641+
<xarray.Dataset>
642+
Dimensions: (temperature: 3)
643+
Coordinates:
644+
* temperature (temperature) int64 25 30 27
645+
Data variables:
646+
*empty*
647+
648+
>>> new_dataset = dataset.assign_attrs(
649+
... units="Celsius", description="Temperature data"
650+
... )
651+
>>> new_dataset
652+
<xarray.Dataset>
653+
Dimensions: (temperature: 3)
654+
Coordinates:
655+
* temperature (temperature) int64 25 30 27
656+
Data variables:
657+
*empty*
658+
Attributes:
659+
units: Celsius
660+
description: Temperature data
661+
662+
# Attributes of the new dataset
663+
664+
>>> new_dataset.attrs
665+
{'units': 'Celsius', 'description': 'Temperature data'}
666+
637667
Returns
638668
-------
639669
assigned : same type as caller

0 commit comments

Comments
 (0)