Conversation
gavinevans
left a comment
There was a problem hiding this comment.
Thanks @maxwhitemet 👍
I've added a few comments.
improver/utilities/cube_checker.py
Outdated
| ValueError: | ||
| If an invalid mode is specified, if required dimensions are missing, or if | ||
| forbidden dimensions are present. |
There was a problem hiding this comment.
We would usually list the different ValueErrors that can be raised separately.
improver/utilities/cube_checker.py
Outdated
|
|
||
| """ | ||
| if mode not in ("exact", "minimum"): | ||
| raise ValueError("mode must be 'exact' or 'minimum'") |
There was a problem hiding this comment.
You could also add the mode that was provided to the exception message.
improver/utilities/cube_checker.py
Outdated
| Resolve dimension tokens to actual dimension coordinate names. 'x' and 'y' are | ||
| treated as axis tokens to resolve, while all other entries are treated as | ||
| explicit dimension coordinate names. |
There was a problem hiding this comment.
Perhaps label would be better than token here, and is the word used in e.g. https://scitools-iris.readthedocs.io/en/stable/generated/api/iris.util.html#iris.util.guess_coord_axis?
| def test_validate_cube_dimensions_raises( | ||
| cube_3d, required_dimensions, forbidden_dimensions, mode, error_message | ||
| ): | ||
| with pytest.raises(ValueError, match=error_message): |
There was a problem hiding this comment.
This test is missing a docstring.
| def test_validate_cube_dimensions_passes( | ||
| cube_3d, required_dimensions, forbidden_dimensions, mode | ||
| ): | ||
| validate_cube_dimensions( |
There was a problem hiding this comment.
This test is missing a docstring.
|
|
||
| @pytest.fixture | ||
| def cube_3d(): | ||
| data = np.ones((2, 1, 1), dtype=np.float32) |
There was a problem hiding this comment.
A short docstring would be good.
maxwhitemet
left a comment
There was a problem hiding this comment.
Thank you for the review @gavinevans. I have implemented all feedback.
improver/utilities/cube_checker.py
Outdated
| ValueError: | ||
| If an invalid mode is specified, if required dimensions are missing, or if | ||
| forbidden dimensions are present. |
improver/utilities/cube_checker.py
Outdated
| Resolve dimension tokens to actual dimension coordinate names. 'x' and 'y' are | ||
| treated as axis tokens to resolve, while all other entries are treated as | ||
| explicit dimension coordinate names. |
|
|
||
| @pytest.fixture | ||
| def cube_3d(): | ||
| data = np.ones((2, 1, 1), dtype=np.float32) |
| def test_validate_cube_dimensions_passes( | ||
| cube_3d, required_dimensions, forbidden_dimensions, mode | ||
| ): | ||
| validate_cube_dimensions( |
| def test_validate_cube_dimensions_raises( | ||
| cube_3d, required_dimensions, forbidden_dimensions, mode, error_message | ||
| ): | ||
| with pytest.raises(ValueError, match=error_message): |
Addresses #1099
Description
This PR adds, and tests, a utility to validate cube dimensions.
Testing: