MCPcopy Create free account
hub / github.com/pydata/xarray / _binary_op

Method _binary_op

xarray/core/dataset.py:7730–7750  ·  view source on GitHub ↗
(self, other, f, reflexive=False, join=None)

Source from the content-addressed store, hash-verified

7728 return self._replace_with_new_dims(variables, attrs=attrs)
7729
7730 def _binary_op(self, other, f, reflexive=False, join=None) -> Dataset:
7731 from xarray.core.dataarray import DataArray
7732 from xarray.core.datatree import DataTree
7733 from xarray.core.groupby import GroupBy
7734
7735 if isinstance(other, DataTree | GroupBy):
7736 return NotImplemented
7737 align_type = OPTIONS["arithmetic_join"] if join is None else join
7738 if isinstance(other, DataArray | Dataset):
7739 self, other = align(self, other, join=align_type, copy=False)
7740 g = f if not reflexive else lambda x, y: f(y, x)
7741 ds = self._calculate_binary_op(g, other, join=align_type)
7742 keep_attrs = _get_keep_attrs(default=True)
7743 if keep_attrs:
7744 # Combine attributes from both operands, dropping conflicts
7745 from xarray.structure.merge import merge_attrs
7746
7747 self_attrs = self.attrs
7748 other_attrs = getattr(other, "attrs", {})
7749 ds.attrs = merge_attrs([self_attrs, other_attrs], "drop_conflicts")
7750 return ds
7751
7752 def _inplace_binary_op(self, other, f) -> Self:
7753 from xarray.core.dataarray import DataArray

Callers

nothing calls this directly

Calls 5

_calculate_binary_opMethod · 0.95
alignFunction · 0.90
_get_keep_attrsFunction · 0.90
merge_attrsFunction · 0.90
fFunction · 0.70

Tested by

no test coverage detected