Skip to content

Commit 64d14f9

Browse files
committed
Add an arithmetic_compat option to xr.set_options, which determines how non-index coordinates of the same name are compared for potential conflicts when performing binary operations.
The default of compat='minimal' matches the previous behaviour.
1 parent bc2e5a0 commit 64d14f9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

doc/whats-new.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ v2025.12.1 (unreleased)
1313

1414
New Features
1515
~~~~~~~~~~~~
16+
17+
- Improved ``pydap`` backend behavior and performance when using :py:func:`open_dataset`, :py:func:`open_datatree`
18+
when downloading dap4 (opendap) dimensions data (:issue:`10628`, :pull:`10629`). In addition ``checksums=True|False``
19+
is added as optional argument to be passed to ``pydap`` backend.
20+
By `Miguel Jimenez-Urias <https://github.com/Mikejmnez>`_.
21+
22+
- :py:func:`combine_nested` now support :py:class:`DataTree` objects
23+
(:pull:`10849`).
24+
By `Stephan Hoyer <https://github.com/shoyer>`_.
1625
- :py:func:`set_options` now supports an ``arithmetic_compat`` option which determines how non-index coordinates
1726
of the same name are compared for potential conflicts when performing binary operations. The default for it is
1827
``arithmetic_compat='minimal'`` which matches the existing behaviour.

xarray/tests/test_datatree.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)