Update this Coordinates variables with other coordinate variables.
(self, other: Mapping[Any, Any])
| 616 | self.update({key: value}) |
| 617 | |
| 618 | def update(self, other: Mapping[Any, Any]) -> None: |
| 619 | """Update this Coordinates variables with other coordinate variables.""" |
| 620 | |
| 621 | if not len(other): |
| 622 | return |
| 623 | |
| 624 | other_coords: Coordinates |
| 625 | |
| 626 | if isinstance(other, Coordinates): |
| 627 | # Coordinates object: just pass it (default indexes won't be created) |
| 628 | other_coords = other |
| 629 | else: |
| 630 | other_coords = create_coords_with_default_indexes( |
| 631 | getattr(other, "variables", other) |
| 632 | ) |
| 633 | |
| 634 | # Discard original indexed coordinates prior to merge allows to: |
| 635 | # - fail early if the new coordinates don't preserve the integrity of existing |
| 636 | # multi-coordinate indexes |
| 637 | # - drop & replace coordinates without alignment (note: we must keep indexed |
| 638 | # coordinates extracted from the DataArray objects passed as values to |
| 639 | # `other` - if any - as those are still used for aligning the old/new coordinates) |
| 640 | coords_to_align = drop_indexed_coords(set(other_coords) & set(other), self) |
| 641 | |
| 642 | coords, indexes = merge_coords( |
| 643 | [coords_to_align, other_coords], |
| 644 | priority_arg=1, |
| 645 | indexes=coords_to_align.xindexes, |
| 646 | ) |
| 647 | |
| 648 | # special case for PandasMultiIndex: updating only its dimension coordinate |
| 649 | # is still allowed but depreciated. |
| 650 | # It is the only case where we need to actually drop coordinates here (multi-index levels) |
| 651 | # TODO: remove when removing PandasMultiIndex's dimension coordinate. |
| 652 | self._drop_coords(self._names - coords_to_align._names) |
| 653 | |
| 654 | self._update_coords(coords, indexes) |
| 655 | |
| 656 | def assign(self, coords: Mapping | None = None, **coords_kwargs: Any) -> Self: |
| 657 | """Assign new coordinates (and indexes) to a Coordinates object, returning |