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

Method _inplace_binary_op

xarray/core/dataarray.py:4929–4954  ·  view source on GitHub ↗
(self, other: DaCompatible, f: Callable)

Source from the content-addressed store, hash-verified

4927 return self._replace(variable, coords, name, indexes=indexes)
4928
4929 def _inplace_binary_op(self, other: DaCompatible, f: Callable) -> Self:
4930 from xarray.core.groupby import GroupBy
4931
4932 if isinstance(other, GroupBy):
4933 raise TypeError(
4934 "in-place operations between a DataArray and "
4935 "a grouped object are not permitted"
4936 )
4937 # n.b. we can't align other to self (with other.reindex_like(self))
4938 # because `other` may be converted into floats, which would cause
4939 # in-place arithmetic to fail unpredictably. Instead, we simply
4940 # don't support automatic alignment with in-place arithmetic.
4941 other_coords = getattr(other, "coords", None)
4942 other_variable = getattr(other, "variable", other)
4943 try:
4944 with self.coords._merge_inplace(
4945 other_coords, compat=OPTIONS["arithmetic_compat"]
4946 ):
4947 f(self.variable, other_variable)
4948 except MergeError as exc:
4949 raise MergeError(
4950 "Automatic alignment is not supported for in-place operations.\n"
4951 "Consider aligning the indices manually or using a not-in-place operation.\n"
4952 "See https://github.com/pydata/xarray/issues/3910 for more explanations."
4953 ) from exc
4954 return self
4955
4956 def _copy_attrs_from(self, other: DataArray | Dataset | Variable) -> None:
4957 self.attrs = other.attrs

Callers

nothing calls this directly

Calls 3

MergeErrorClass · 0.90
_merge_inplaceMethod · 0.80
fFunction · 0.70

Tested by

no test coverage detected