Skip to content

Commit 351b0aa

Browse files
authored
document update as inplace (#4932)
* explicitly state that update works inplace * point to assign * update whats-new.rst [skip-ci] * rewrite the docstring [skip-ci] * deprecate the return value of Dataset.update * add the issue and pull request numbers [skip-ci] * add a ETA for the removal of the return value [skip-ci]
1 parent 63f2e5d commit 351b0aa

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Deprecations
7979
For now using ``dim`` issues a ``FutureWarning``. It will be removed in
8080
version 0.19.0 (:pull:`3993`).
8181
By `Tom Nicholas <https://github.com/TomNicholas>`_.
82+
- the return value of :py:meth:`Dataset.update` is being deprecated to make it work more
83+
like :py:meth:`dict.update`. It will be removed in version 0.19.0 (:pull:`4932`).
84+
By `Justus Magin <https://github.com/keewis>`_.
8285

8386

8487
New Features
@@ -181,6 +184,8 @@ Documentation
181184
- add concat examples and improve combining documentation (:issue:`4620`, :pull:`4645`).
182185
By `Ray Bell <https://github.com/raybellwaves>`_ and
183186
`Justus Magin <https://github.com/keewis>`_.
187+
- explicitly mention that :py:meth:`Dataset.update` updates inplace (:issue:`2951`, :pull:`4932`).
188+
By `Justus Magin <https://github.com/keewis>`_.
184189

185190
Internal Changes
186191
~~~~~~~~~~~~~~~~

xarray/core/dataset.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3865,6 +3865,8 @@ def unstack(
38653865
def update(self, other: "CoercibleMapping") -> "Dataset":
38663866
"""Update this dataset's variables with those from another dataset.
38673867
3868+
Just like :py:meth:`dict.update` this is a in-place operation.
3869+
38683870
Parameters
38693871
----------
38703872
other : Dataset or mapping
@@ -3879,13 +3881,20 @@ def update(self, other: "CoercibleMapping") -> "Dataset":
38793881
Returns
38803882
-------
38813883
updated : Dataset
3882-
Updated dataset.
3884+
Updated dataset. Note that since the update is in-place this is the input
3885+
dataset.
3886+
3887+
It is deprecated since version 0.17 and scheduled to be removed in 0.19.
38833888
38843889
Raises
38853890
------
38863891
ValueError
38873892
If any dimensions would have inconsistent sizes in the updated
38883893
dataset.
3894+
3895+
See Also
3896+
--------
3897+
Dataset.assign
38893898
"""
38903899
merge_result = dataset_update_method(self, other)
38913900
return self._replace(inplace=True, **merge_result._asdict())

0 commit comments

Comments
 (0)