Maybe replace indexes and their corresponding coordinates.
(
self,
indexes: Mapping[Any, Index],
variables: Mapping[Any, Variable] | None = None,
drop_coords: list[Hashable] | None = None,
rename_dims: Mapping[Any, Any] | None = None,
)
| 549 | return self._replace(variable, coords, name, indexes=indexes) |
| 550 | |
| 551 | def _overwrite_indexes( |
| 552 | self, |
| 553 | indexes: Mapping[Any, Index], |
| 554 | variables: Mapping[Any, Variable] | None = None, |
| 555 | drop_coords: list[Hashable] | None = None, |
| 556 | rename_dims: Mapping[Any, Any] | None = None, |
| 557 | ) -> Self: |
| 558 | """Maybe replace indexes and their corresponding coordinates.""" |
| 559 | if not indexes: |
| 560 | return self |
| 561 | |
| 562 | if variables is None: |
| 563 | variables = {} |
| 564 | if drop_coords is None: |
| 565 | drop_coords = [] |
| 566 | |
| 567 | new_variable = self.variable.copy() |
| 568 | new_coords = self._coords.copy() |
| 569 | new_indexes = dict(self._indexes) |
| 570 | |
| 571 | for name in indexes: |
| 572 | new_coords[name] = variables[name] |
| 573 | new_indexes[name] = indexes[name] |
| 574 | |
| 575 | for name in drop_coords: |
| 576 | new_coords.pop(name) |
| 577 | new_indexes.pop(name) |
| 578 | |
| 579 | if rename_dims: |
| 580 | new_variable.dims = tuple(rename_dims.get(d, d) for d in new_variable.dims) |
| 581 | |
| 582 | return self._replace( |
| 583 | variable=new_variable, coords=new_coords, indexes=new_indexes |
| 584 | ) |
| 585 | |
| 586 | def _to_temp_dataset(self) -> Dataset: |
| 587 | return self._to_dataset_whole(name=_THIS_ARRAY, shallow_copy=False) |