Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tom-welfonder
Copy link

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.

Add function to ensure that added variables do not use unvalid dimension names.
Copy link
Member

@lkstrp lkstrp left a 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.

Comment on lines +380 to +383
contains_unsupported_dim_names = any(
dim in unsupported_dim_names for dim in list(ds.dims)
)
if contains_unsupported_dim_names:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Comment on lines +388 to +389
else:
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.check_valid_dim_names(data)
self._check_valid_dim_names(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants