Returns a new object with renamed variables including coordinates Parameters ---------- name_dict : dict-like, optional Dictionary whose keys are current variable or coordinate names and whose values are the desired names. **names : optional
(
self,
name_dict: Mapping[Any, Hashable] | None = None,
**names: Hashable,
)
| 4333 | return self._replace(variables, coord_names, dims=sizes, indexes=indexes) |
| 4334 | |
| 4335 | def rename_vars( |
| 4336 | self, |
| 4337 | name_dict: Mapping[Any, Hashable] | None = None, |
| 4338 | **names: Hashable, |
| 4339 | ) -> Self: |
| 4340 | """Returns a new object with renamed variables including coordinates |
| 4341 | |
| 4342 | Parameters |
| 4343 | ---------- |
| 4344 | name_dict : dict-like, optional |
| 4345 | Dictionary whose keys are current variable or coordinate names and |
| 4346 | whose values are the desired names. |
| 4347 | **names : optional |
| 4348 | Keyword form of ``name_dict``. |
| 4349 | One of name_dict or names must be provided. |
| 4350 | |
| 4351 | Returns |
| 4352 | ------- |
| 4353 | renamed : Dataset |
| 4354 | Dataset with renamed variables including coordinates |
| 4355 | |
| 4356 | See Also |
| 4357 | -------- |
| 4358 | Dataset.swap_dims |
| 4359 | Dataset.rename |
| 4360 | Dataset.rename_dims |
| 4361 | DataArray.rename |
| 4362 | """ |
| 4363 | name_dict = either_dict_or_kwargs(name_dict, names, "rename_vars") |
| 4364 | for k in name_dict: |
| 4365 | if k not in self: |
| 4366 | raise ValueError( |
| 4367 | f"cannot rename {k!r} because it is not a " |
| 4368 | "variable or coordinate in this dataset" |
| 4369 | ) |
| 4370 | variables, coord_names, dims, indexes = self._rename_all( |
| 4371 | name_dict=name_dict, dims_dict={} |
| 4372 | ) |
| 4373 | return self._replace(variables, coord_names, dims=dims, indexes=indexes) |
| 4374 | |
| 4375 | def swap_dims( |
| 4376 | self, dims_dict: Mapping[Any, Hashable] | None = None, **dims_kwargs |