Skip to content

Commit

Permalink
ds.merge(da) bugfix (#3677)
Browse files Browse the repository at this point in the history
* Added mwe as test

* Cast to Dataset

* Updated what's new

* black formatted

* Use assert_identical
  • Loading branch information
TomNicholas authored Jan 12, 2020
1 parent 40fab1b commit 1689db4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Bug fixes
By `Justus Magin <https://github.com/keewis>`_.
- :py:meth:`Dataset.rename`, :py:meth:`DataArray.rename` now check for conflicts with
MultiIndex level names.
- :py:meth:`Dataset.merge` no longer fails when passed a `DataArray` instead of a `Dataset` object.
By `Tom Nicholas <https://github.com/TomNicholas>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3607,6 +3607,7 @@ def merge(
If any variables conflict (see ``compat``).
"""
_check_inplace(inplace)
other = other.to_dataset() if isinstance(other, xr.DataArray) else other
merge_result = dataset_merge_method(
self,
other,
Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import xarray as xr
from xarray.core import dtypes, merge
from xarray.testing import assert_identical

from . import raises_regex
from .test_dataset import create_test_data
Expand Down Expand Up @@ -253,3 +254,9 @@ def test_merge_no_conflicts(self):
with pytest.raises(xr.MergeError):
ds3 = xr.Dataset({"a": ("y", [2, 3]), "y": [1, 2]})
ds1.merge(ds3, compat="no_conflicts")

def test_merge_dataarray(self):
ds = xr.Dataset({"a": 0})
da = xr.DataArray(data=1, name="b")

assert_identical(ds.merge(da), xr.merge([ds, da]))

0 comments on commit 1689db4

Please sign in to comment.