File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1834,7 +1834,29 @@ def test_arithmetic_inherited_coords(self):
1834
1834
expected ["/foo/bar" ].data = np .array ([8 , 10 , 12 ])
1835
1835
assert_identical (actual , expected )
1836
1836
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 )
1838
1860
1839
1861
# TODO test single-node datatree doesn't broadcast
1840
1862
You can’t perform that action at this time.
0 commit comments