Uh oh!
There was an error while loading. Please reload this page.
Update DataArray.rename + docu - #6665
Conversation
headtr1ck
commented
Jun 5, 2022
Mow you can also have the name of the DataArray in the rename dict. |
headtr1ck
commented
Jun 5, 2022
Now that I think about it... |
headtr1ck
commented
Jun 8, 2022
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. |
max-sixty
commented
Jun 8, 2022
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? |
keewis
commented
Jun 8, 2022
in |
We do want it to be fluent though, so it can be directly on the (
da
.rename(...)
.sum(...)
) |
headtr1ck
commented
Jun 9, 2022
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 nameb=xr.DataArray([0, 1, 2], dims="x", name="b")
b.rename("new")
b.rename(b="new") # b is the current name# with coordsc=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 |
headtr1ck
commented
Jun 11, 2022
I will implement a I am not sure about |
max-sixty
commented
Jun 11, 2022
@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? |
keewis
commented
Jun 11, 2022
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. |
headtr1ck
commented
Jun 12, 2022
Ok I see. I hereby withdraw my comment that it will be trivial, haha. |
headtr1ck
commented
Jun 13, 2022
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? |
max-sixty
commented
Jun 13, 2022
Yes great, let's merge this.
Then two main options I see for synthesizing the vars issues:
|
headtr1ck
commented
Jun 18, 2022
I have created #6704 and tried to copy a summary of this discussion. |
Illviljan
commented
Jul 18, 2022
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.rstOn 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.