Skip to content

Commit 03ce2c5

Browse files
committed
ensure other types defer to DataTree, thus fixing pydata#9365
1 parent 909ae0e commit 03ce2c5

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

xarray/core/dataarray.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4765,9 +4765,10 @@ def _unary_op(self, f: Callable, *args, **kwargs) -> Self:
47654765
def _binary_op(
47664766
self, other: DaCompatible, f: Callable, reflexive: bool = False
47674767
) -> Self:
4768+
from xarray.core.datatree import DataTree
47684769
from xarray.core.groupby import GroupBy
47694770

4770-
if isinstance(other, Dataset | GroupBy):
4771+
if isinstance(other, DataTree | Dataset | GroupBy):
47714772
return NotImplemented
47724773
if isinstance(other, DataArray):
47734774
align_type = OPTIONS["arithmetic_join"]

xarray/core/dataset.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7784,9 +7784,10 @@ def _unary_op(self, f, *args, **kwargs) -> Self:
77847784

77857785
def _binary_op(self, other, f, reflexive=False, join=None) -> Dataset:
77867786
from xarray.core.dataarray import DataArray
7787+
from xarray.core.datatree import DataTree
77877788
from xarray.core.groupby import GroupBy
77887789

7789-
if isinstance(other, GroupBy):
7790+
if isinstance(other, DataTree | GroupBy):
77907791
return NotImplemented
77917792
align_type = OPTIONS["arithmetic_join"] if join is None else join
77927793
if isinstance(other, DataArray | Dataset):

xarray/core/variable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,7 @@ def _unary_op(self, f, *args, **kwargs):
23232323
return result
23242324

23252325
def _binary_op(self, other, f, reflexive=False):
2326-
if isinstance(other, xr.DataArray | xr.Dataset):
2326+
if isinstance(other, xr.DataTree | xr.DataArray | xr.Dataset):
23272327
return NotImplemented
23282328
if reflexive and issubclass(type(self), type(other)):
23292329
other_data, self_data, dims = _broadcast_compat_data(other, self)

0 commit comments

Comments
 (0)