-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
modification methods on Coordinates
#10318
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
base: main
Are you sure you want to change the base?
Conversation
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.
LGTM, those methods seem like a useful addition to me. Left a few minor comments.
renamed : Dataset | ||
Dataset with renamed variables including coordinates |
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.
renamed : Dataset | |
Dataset with renamed variables including coordinates | |
renamed : Coordinates | |
Coordinates object with renamed variables |
name_dict: Mapping[Any, Hashable] | None = None, | ||
**names: Hashable, | ||
) -> Self: | ||
"""Returns a new object with renamed variables including coordinates |
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.
"""Returns a new object with renamed variables including coordinates | |
"""Returns a new object with renamed variables. |
@@ -561,6 +561,31 @@ def merge(self, other: Mapping[Any, Any] | None) -> Dataset: | |||
variables=coords, coord_names=coord_names, indexes=indexes | |||
) | |||
|
|||
def __or__(self, other: Self) -> Self: | |||
"""Merge two sets of coordinates to create a new Coordinates object |
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.
Do we need such docstrings for an operator?
renamed : Coordinates | ||
Coordinates object with renamed dimensions. | ||
""" | ||
return self.to_dataset().rename_dims(dims_dict, **dims).coords |
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.
self._data
would have prevented duplicated copy of the wrapped Dataset, but it won't work with the DataArrayCoordinates subclass so I guess self.to_dataset()
is fine.
dims_dict : dict-like, optional | ||
Dictionary whose keys are current dimension names and | ||
whose values are the desired names. The desired names must | ||
not be the name of an existing dimension or Variable in the Dataset. |
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.
not be the name of an existing dimension or Variable in the Dataset. | |
not be the name of an existing dimension or Variable in the Coordinates. |
For ease of use, this implements a few additional methods on
Coordinates
:rename_dims
rename_vars
drop_vars
coords1 | coords2
as an alias ofcoords1.merge(coords2)
These currently forward to the implementation in
Dataset
, but will be the natural place after refactoringCoordinates
to not wrap aDataset
.Coordinates
operations #10314whats-new.rst
api.rst
cc @benbovy, @scottyhq