MCPcopy
hub / github.com/pydata/xarray / _binary_op

Method _binary_op

xarray/core/variable.py:2444–2467  ·  view source on GitHub ↗
(self, other, f, reflexive=False)

Source from the content-addressed store, hash-verified

2442 return result
2443
2444 def _binary_op(self, other, f, reflexive=False):
2445 if isinstance(other, xr.DataTree | xr.DataArray | xr.Dataset):
2446 return NotImplemented
2447 if reflexive and issubclass(type(self), type(other)):
2448 other_data, self_data, dims = _broadcast_compat_data(other, self)
2449 else:
2450 self_data, other_data, dims = _broadcast_compat_data(self, other)
2451 keep_attrs = _get_keep_attrs(default=True)
2452 if keep_attrs:
2453 # Combine attributes from both operands, dropping conflicts
2454 from xarray.structure.merge import merge_attrs
2455
2456 # Access attrs property to normalize None to {} due to property side effect
2457 self_attrs = self.attrs
2458 other_attrs = getattr(other, "attrs", {})
2459 attrs = merge_attrs([self_attrs, other_attrs], "drop_conflicts")
2460 else:
2461 attrs = None
2462 with np.errstate(all="ignore"):
2463 new_data = (
2464 f(self_data, other_data) if not reflexive else f(other_data, self_data)
2465 )
2466 result = Variable(dims, new_data, attrs=attrs)
2467 return result
2468
2469 def _inplace_binary_op(self, other, f):
2470 if isinstance(other, xr.Dataset):

Callers

nothing calls this directly

Calls 6

_get_keep_attrsFunction · 0.90
merge_attrsFunction · 0.90
typeFunction · 0.85
_broadcast_compat_dataFunction · 0.85
fFunction · 0.70
VariableClass · 0.70

Tested by

no test coverage detected