Add Field tests and type guarding in Field init#1986
Merged
VeckoTheGecko merged 8 commits intov4-devfrom Apr 29, 2025
Merged
Conversation
Opt for `add_note` instead
VeckoTheGecko
commented
Apr 24, 2025
Comment on lines
685
to
697
| def _validate_uxgrid(grid): | ||
| """Verifies that all the required attributes are present in the uxarray.UxDataArray.UxGrid object.""" | ||
| if "Conventions" not in grid.attrs.keys(): | ||
| raise ValueError( | ||
| f"Field {name} is missing a 'Conventions' attribute in the field's metadata. " | ||
| "Field is missing a 'Conventions' attribute in the field's metadata. " | ||
| "This attribute is required for uxarray.UxDataArray objects." | ||
| ) | ||
| if grid.attrs["Conventions"] != "UGRID-1.0": | ||
| raise ValueError( | ||
| f"Field {name} has a 'Conventions' attribute that is not 'UGRID-1.0'. " | ||
| "Field has a 'Conventions' attribute that is not 'UGRID-1.0'. " | ||
| "This attribute is required for uxarray.UxDataArray objects." | ||
| "See https://ugrid-conventions.github.io/ugrid-conventions/ for more information." | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
I think its nice removing name from here as it's only used in the error message itself. The context can be added via add_note (introduced in 3.11) as the message propagates up
5206c57 to
eab6cc5
Compare
fluidnumericsJoe
approved these changes
Apr 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does some cleanup in the
field.pyfile, adds type guarding in the Field initialiser, and adds some tests for, laying some of the prep work for structured grid compatability in the Field object.v4-devfor v4 changes)