@@ -2423,6 +2423,43 @@ def test_arithmetic_inherited_coords(self) -> None:
24232423 expected ["/foo/bar" ].data = np .array ([8 , 10 , 12 ])
24242424 assert_identical (actual , expected )
24252425
2426+ def test_binary_op_compat_setting (self ) -> None :
2427+ # Setting up a clash of non-index coordinate 'foo':
2428+ a = DataTree (xr .Dataset (
2429+ data_vars = {"var" : (["x" ], [0 , 0 , 0 ])},
2430+ coords = {
2431+ "x" : [1 , 2 , 3 ],
2432+ "foo" : (["x" ], [1.0 , 2.0 , np .nan ]),
2433+ },
2434+ ))
2435+ b = DataTree (xr .Dataset (
2436+ data_vars = {"var" : (["x" ], [0 , 0 , 0 ])},
2437+ coords = {
2438+ "x" : [1 , 2 , 3 ],
2439+ "foo" : (["x" ], [np .nan , 2.0 , 3.0 ]),
2440+ },
2441+ ))
2442+
2443+ with xr .set_options (arithmetic_compat = "minimal" ):
2444+ expected = DataTree (a .dataset .drop_vars ('foo' ))
2445+ assert_equal (a + b , expected )
2446+
2447+ with xr .set_options (arithmetic_compat = "override" ):
2448+ assert_equal (a + b , a )
2449+ assert_equal (b + a , b )
2450+
2451+ with xr .set_options (arithmetic_compat = "no_conflicts" ):
2452+ expected = DataTree (a .dataset .assign_coords (
2453+ foo = (["x" ], [1.0 , 2.0 , 3.0 ])))
2454+ assert_equal (a + b , expected )
2455+ assert_equal (b + a , expected )
2456+
2457+ with xr .set_options (arithmetic_compat = "equals" ):
2458+ with pytest .raises (xr .MergeError ):
2459+ a + b
2460+ with pytest .raises (xr .MergeError ):
2461+ b + a
2462+
24262463 def test_binary_op_commutativity_with_dataset (self ) -> None :
24272464 # regression test for #9365
24282465
0 commit comments