Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible indexes: handle renaming coordinate variables #5645

Closed
benbovy opened this issue Jul 29, 2021 · 0 comments · Fixed by #5692
Closed

Flexible indexes: handle renaming coordinate variables #5645

benbovy opened this issue Jul 29, 2021 · 0 comments · Fixed by #5692

Comments

@benbovy
Copy link
Member

benbovy commented Jul 29, 2021

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:

xarray/xarray/core/dataset.py

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.

@benbovy benbovy mentioned this issue Sep 10, 2021
54 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant