-
Notifications
You must be signed in to change notification settings - Fork 51
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
add check for valid dimension name before creating new variable #360
base: master
Are you sure you want to change the base?
Conversation
Add function to ensure that added variables do not use unvalid dimension names.
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.
Hey @tom-welfonder, thanks for the contribution! And sorry for taking a while. That looks like a useful check. Just some minor things.
contains_unsupported_dim_names = any( | ||
dim in unsupported_dim_names for dim in list(ds.dims) | ||
) | ||
if contains_unsupported_dim_names: |
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.
contains_unsupported_dim_names = any( | |
dim in unsupported_dim_names for dim in list(ds.dims) | |
) | |
if contains_unsupported_dim_names: | |
if any(dim in unsupported_dim_names for dim in ds.dims): |
Maybe a little more condensed?
else: | ||
return |
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.
else: | |
return |
@@ -357,6 +357,37 @@ def check_force_dim_names(self, ds: DataArray | Dataset) -> None: | |||
else: | |||
return | |||
|
|||
def check_valid_dim_names(self, ds: DataArray | Dataset) -> None: |
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.
def check_valid_dim_names(self, ds: DataArray | Dataset) -> None: | |
def _check_valid_dim_names(self, ds: DataArray | Dataset) -> None: |
@@ -464,6 +495,7 @@ def add_variables( | |||
) | |||
(data,) = xr.broadcast(data) | |||
self.check_force_dim_names(data) | |||
self.check_valid_dim_names(data) |
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.check_valid_dim_names(data) | |
self._check_valid_dim_names(data) |
Add function to ensure that added variables do not use unvalid dimension names.
Add test for variable assignment with invalid dimension name.
This code adds a more meaning full error message if users try to create new variables with invalid dimension names.
Old behavior is described in #359.