|
53 | 53 | from .formatting import format_item
|
54 | 54 | from .indexes import Indexes, default_indexes, propagate_indexes
|
55 | 55 | from .indexing import is_fancy_indexer
|
56 |
| -from .merge import PANDAS_TYPES, _extract_indexes_from_coords |
| 56 | +from .merge import PANDAS_TYPES, MergeError, _extract_indexes_from_coords |
57 | 57 | from .options import OPTIONS
|
58 | 58 | from .utils import Default, ReprObject, _check_inplace, _default, either_dict_or_kwargs
|
59 | 59 | from .variable import (
|
@@ -2713,8 +2713,15 @@ def func(self, other):
|
2713 | 2713 | # don't support automatic alignment with in-place arithmetic.
|
2714 | 2714 | other_coords = getattr(other, "coords", None)
|
2715 | 2715 | other_variable = getattr(other, "variable", other)
|
2716 |
| - with self.coords._merge_inplace(other_coords): |
2717 |
| - f(self.variable, other_variable) |
| 2716 | + try: |
| 2717 | + with self.coords._merge_inplace(other_coords): |
| 2718 | + f(self.variable, other_variable) |
| 2719 | + except MergeError as exc: |
| 2720 | + raise MergeError( |
| 2721 | + "Automatic alignment is not supported for in-place operations.\n" |
| 2722 | + "Consider aligning the indices manually or using a not-in-place operation.\n" |
| 2723 | + "See https://github.com/pydata/xarray/issues/3910 for more explanations." |
| 2724 | + ) from exc |
2718 | 2725 | return self
|
2719 | 2726 |
|
2720 | 2727 | return func
|
|
0 commit comments