Skip to content

Commit 909ae0e

Browse files
committed
test ds * dt commutativity
1 parent 8e7c1da commit 909ae0e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

xarray/tests/test_datatree.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,29 @@ def test_arithmetic_inherited_coords(self):
18341834
expected["/foo/bar"].data = np.array([8, 10, 12])
18351835
assert_identical(actual, expected)
18361836

1837-
# TODO test dataset * datatree commutativity
1837+
def test_binary_op_commutativity_with_dataset(self):
1838+
# regression test for #9365
1839+
1840+
ds1 = xr.Dataset({"a": [5], "b": [3]})
1841+
ds2 = xr.Dataset({"x": [0.1, 0.2], "y": [10, 20]})
1842+
dt = DataTree.from_dict(
1843+
{
1844+
"/": ds1,
1845+
"/subnode": ds2,
1846+
}
1847+
)
1848+
1849+
other_ds = xr.Dataset({"z": ("z", [0.1, 0.2])})
1850+
1851+
expected = DataTree.from_dict(
1852+
{
1853+
"/": ds1 * other_ds,
1854+
"/subnode": ds2 * other_ds,
1855+
}
1856+
)
1857+
1858+
result = other_ds * dt
1859+
assert_equal(result, expected)
18381860

18391861
# TODO test single-node datatree doesn't broadcast
18401862

0 commit comments

Comments
 (0)