-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added rename_coords and rename_dims #3042
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
Conversation
|
Hello @jukent! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-06-25 20:30:26 UTC |
|
There is some unexpected behavior. The new rename_dims function does not change the dimensions of the variables. Working on this now. |
Similarly rename_vars will rename the variable dimensions and variables, but not the dataset dimensions. I thought I was dealing with this with the _rename_indexes. But will have to keep working. |
xarray/core/dataset.py
Outdated
| return self._replace(dims=dims, indexes=indexes, inplace=inplace) | ||
|
|
||
|
|
||
| def rename_vars(self, name_dict=None, inplace=None, **names): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do people think about vars vs variables here?
I'm +0.2 on variables for consistency with merge_variables etc (but only did a quick search, I would update if there were more public vars methods around)
xarray/core/dataset.py
Outdated
| name_dict : dict-like, optional | ||
| Dictionary whose keys are current variable or coordinate names and | ||
| whose values are the desired names. | ||
| inplace : bool, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given inplace has been deprecated, I don't think we should add it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I removed it, but it is still floating around in the other functions in the script (swap_dims for example)
|
This is great! Thanks @jukent ! Ping back here if there's anything we can do to help |
|
And tbc, we should add tests here. That will help clarify the issues above re exactly which items on the dataset each method should rename vs leave. |
Yes I need to add tests, but I don't have much experience with this yet. I will ask my team here to help me. |
This works now! But to do so I created three different renaming variable helper functions (var name only, var and dims, var dims only). I will clean this up since the majority of these three functions is the same. |
|
@jukent check out the existing rename tests here (they're a bit over-complicated at the beginning): https://github.com/pydata/xarray/blob/master/xarray/tests/test_dataset.py#L2046-L2130 You could do something as simple as this: https://github.com/pydata/xarray/blob/master/xarray/tests/test_dataset.py#L2114-L2119 - i.e. start with a dataset, call a rename method, and compare the dataset with a manually constructed version of the expected result. Ping back with any issues |
Thanks @max-sixty. I added some very simple tests. I might copy more of the test_rename functions (if I tried to rename a variable to the same name for example) |
|
Those look great! |
|
@jukent I don't think that's our bot |
whats-new.rstfor all changes andapi.rstfor new API