-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
We should have some API in xarray.Index to update the index when its corresponding coordinate variables are renamed.
This currently implemented here where the underlying pd.Index name(s) are updated:
Lines 3299 to 3314 in c5530d5
| def _rename_indexes(self, name_dict, dims_set): | |
| if self._indexes is None: | |
| return None | |
| indexes = {} | |
| for k, v in self.xindexes.items(): | |
| # TODO: benbovy - flexible indexes: make it compatible with any xarray Index | |
| index = v.to_pandas_index() | |
| new_name = name_dict.get(k, k) | |
| if new_name not in dims_set: | |
| continue | |
| if isinstance(index, pd.MultiIndex): | |
| new_names = [name_dict.get(k, k) for k in index.names] | |
| indexes[new_name] = PandasMultiIndex(index.rename(names=new_names)) | |
| else: | |
| indexes[new_name] = PandasIndex(index.rename(new_name)) | |
| return indexes |
This logic should be moved into PandasIndex and PandasMultiIndex.
Other, custom indexes might also have internal attributes to update, so we might need formal API for that.