-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update DataArray.rename + docu #6665
Conversation
Mow you can also have the name of the DataArray in the rename dict. |
Now that I think about it... |
Now the behavior is the same as before with the only addition that one can rename the DataArray with a positional argument and its cords/dims via kwargs at the same time. I have added further tests that are a bit more expressive than before. Should be ready to merge now. |
This seems like a nice improvement given the existing state. I've found the effort to specialize methods (e.g.
...which is not ideal, though might be the best tradeoff. WDYT @headtr1ck ? Or any other thoughts from others? |
in |
We do want it to be fluent though, so it can be directly on the (
da
.rename(...)
.sum(...)
) |
Honestly I am a big fan of functions that are called the same for DataArray and Dataset since this enables workflows on objects that could be either. A |
I was referring to the concept rather than the method. The idea is that you can refer to the a = xr.DataArray([0, 1, 2], dims="x")
a.rename("new")
a.rename({None: "new"}) # None is the current name
b = xr.DataArray([0, 1, 2], dims="x", name="b")
b.rename("new")
b.rename(b="new") # b is the current name
# with coords
c = xr.DataArray([0, 1, 2], dims="x", coords={"x": ["a", "b", "c"]}, name="c")
c.rename("new", x="y")
c.rename(c="new", x="y")
c.rename({"c": "new", "x": "y"}) # providing both the `dict` and the kwargs raises |
I will implement a I am not sure about |
@keewis v interesting suggestion — the object name as positional and vars as kwargs. As I think was mentioned above, one choice is whether a kwarg with the name of the object renames the object. I would worry it's slightly ambiguous. And potentially not additive. WDYT?
This could be good. Would this also rename the coord associated with the dim? |
To decide that we probably need to figure out what the role of a dimension will be after the index refactor. Before the refactor, we needed to rename the dimension coordinate along with the dimension to keep the index, but now that indexes are independent of dimensions it might be fine not to do that. |
Ok I see. I hereby withdraw my comment that it will be trivial, haha. |
So, how about we leave the current implemention like it is (or merge this PR, it does not really change the core functionality). And then open another issue on how to procede with rename in light of the index refactor? |
Yes great, let's merge this.
Then two main options I see for synthesizing the vars issues:
|
I have created #6704 and tried to copy a summary of this discussion. |
Thanks @headtr1ck ! |
* main: (313 commits) Update whats-new Release notes for v2022.06.0 (pydata#6815) Drop multi-indexes when assigning to a multi-indexed variable (pydata#6798) Support NumPy array API (experimental) (pydata#6804) Add cumsum to DatasetGroupBy (pydata#6525) Refactor groupby binary ops code. (pydata#6789) Update DataArray.rename + docu (pydata#6665) Switch to T_DataArray and T_Dataset in concat (pydata#6784) Fix typos found by codespell (pydata#6794) Update groupby attrs tests (pydata#6787) Update map_blocks to use chunksizes property. (pydata#6776) Fix `DataArrayRolling.__iter__` with `center=True` (pydata#6744) [test-upstream] Update flox repo URL (pydata#6780) Move _infer_meta_data and _parse_size to utils (pydata#6779) Make the `sel` error more descriptive when `method` is unset (pydata#6774) Move Rolling tests to their own testing module (pydata#6777) [pre-commit.ci] pre-commit autoupdate (pydata#6773) move da and ds fixtures to conftest.py (pydata#6730) Bump EnricoMi/publish-unit-test-result-action from 1 to 2 (pydata#6770) Type shape methods (pydata#6767) ...
whats-new.rst
On the way, I have added the support for changing the name and dims/coords in the same rename call.
Also took the freedom to fix some unrelated typing problems.