Update DataArray.rename + docu by headtr1ck · Pull Request #6665 · pydata/xarray (original) (raw)
We do want it to be fluent though, so it can be directly on the
DataArray
, otherwise you can't do:
I was referring to the concept rather than the method. The idea is that you can refer to the DataArray
by positional or by name, and the method takes either a single string or a dict
mapping old names to new names, also with a kwargs version (the merging happens with either_dict_or_kwargs
). That would mean these all do the same thing:
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