Skip to content

Commit

Permalink
ensure other types defer to DataTree, thus fixing pydata#9365
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Oct 13, 2024
1 parent 909ae0e commit 03ce2c5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4765,9 +4765,10 @@ def _unary_op(self, f: Callable, *args, **kwargs) -> Self:
def _binary_op(
self, other: DaCompatible, f: Callable, reflexive: bool = False
) -> Self:
from xarray.core.datatree import DataTree
from xarray.core.groupby import GroupBy

if isinstance(other, Dataset | GroupBy):
if isinstance(other, DataTree | Dataset | GroupBy):
return NotImplemented
if isinstance(other, DataArray):
align_type = OPTIONS["arithmetic_join"]
Expand Down
3 changes: 2 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7784,9 +7784,10 @@ def _unary_op(self, f, *args, **kwargs) -> Self:

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

if isinstance(other, GroupBy):
if isinstance(other, DataTree | GroupBy):
return NotImplemented
align_type = OPTIONS["arithmetic_join"] if join is None else join
if isinstance(other, DataArray | Dataset):
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ def _unary_op(self, f, *args, **kwargs):
return result

def _binary_op(self, other, f, reflexive=False):
if isinstance(other, xr.DataArray | xr.Dataset):
if isinstance(other, xr.DataTree | xr.DataArray | xr.Dataset):
return NotImplemented
if reflexive and issubclass(type(self), type(other)):
other_data, self_data, dims = _broadcast_compat_data(other, self)
Expand Down

0 comments on commit 03ce2c5

Please sign in to comment.