-
Notifications
You must be signed in to change notification settings - Fork 284
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
Update to cell_method
parsing
#6083
Conversation
8b89072
to
c7fc92a
Compare
Also added new unit test to check cell_methods with: 1. Name only (no colon and method) 2. Not space between colon separator and method.
for more information, see https://pre-commit.ci
3702ca4
to
41d4c79
Compare
Modified slightly to address some failing unit tests. |
From @SciTools/peloton: Related to #5165. At the very least there needs to be an informative warning, otherwise what's the point in Iris being strict about CF. Also, if the CF checker is OK with this, maybe we should be OK with it also? @pp-mo would love your opinion on the CF checker's place in these decisions. It could be in this case that CF actually doesn't care about the space (why should it), but just that all the examples have one because it's a bit easier to read. |
From @SciTools/peloton we are accepting this as CF-compliant. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6083 +/- ##
=======================================
Coverage 89.81% 89.82%
=======================================
Files 88 88
Lines 23181 23185 +4
Branches 4313 4314 +1
=======================================
+ Hits 20821 20825 +4
Misses 1628 1628
Partials 732 732 ☔ View full report in Codecov by Sentry. |
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.
Thanks @ukmo-ccbunney, changes all look good to me! I think it's worth just adding a small whatsnew entry for this, then it'll be good to go!
Done. |
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.
Wrong PR number!
Co-authored-by: Elias <[email protected]>
* main: [pre-commit.ci] pre-commit autoupdate (SciTools#6175) Updated environment lockfiles (SciTools#6183) Update to `cell_method` parsing (SciTools#6083) Bump scitools/workflows from 2024.10.0 to 2024.10.1 (SciTools#6179) `colorbar` keyword for iris.quickplot routines (SciTools#6169) Make Iris backwards compatible with Cartopy (SciTools#6172) Updated environment lockfiles (SciTools#6173) Bump scitools/workflows from 2024.09.9 to 2024.10.0 (SciTools#6170) Update lock files, pin Cartopy!=0.23 (SciTools#6171)
* upstream/main: (194 commits) Restore latest Whats New files. [pre-commit.ci] pre-commit autoupdate (SciTools#6205) correct major minor in whatsnew (SciTools#6202) What's new updates for v3.11.0rc0 . (SciTools#6201) Update CF standard names table. (SciTools#6200) Specify meta in dask.array.map_blocks (SciTools#5989) added in a vertical rule for surface fields (SciTools#5734) Updated environment lockfiles (SciTools#6197) Reduce duplication in cf.py spanning checks. (SciTools#6196) Fix attribute array comparison (SciTools#6181) Enable factory references to create new dimensions on load. (SciTools#6168) (SciTools#6194) Improve handling of masks in concatenate (SciTools#6187) Demo Numpy v2 (SciTools#6035) Bump scitools/workflows from 2024.10.1 to 2024.10.2 (SciTools#6186) Document use of new_axis to control merge (SciTools#6180) Updated environment lockfiles (SciTools#6184) [pre-commit.ci] pre-commit autoupdate (SciTools#6175) Updated environment lockfiles (SciTools#6183) Update to `cell_method` parsing (SciTools#6083) Bump scitools/workflows from 2024.10.0 to 2024.10.1 (SciTools#6179) ...
🚀 Pull Request
Description
Iris fails to load cubes from a netCDF file if the
cell_method
attribute is malformed and throws this slightly unhelpful error:For the netCDF files in my particular case, inspection of the stack trace reveals it was failing to correctly parse the
cell_method
attribute which was missing a space between the colon separator and time method. I.e.rather than:
This PR makes two changes to the cell method parsing in
fileformats/_nc_load_rules/helpers.py
:In
_split_cell_methods
: If the value ofcell_methods
does not match the expectedname:
pattern, aWarning
is issued and the function returns an empty list so cube loading can continue. This is consistent with the behaviour further down the function if thename: value
pattern cannot be matched.Updates
_CM_PARSE_NAME
and_CM_PARSE
regexes to make the pattern matching a little more lenient by making the space after the colon separator between thename
andmethod
pair optional. The CF Convention states that the pairs are "blank-separated list ofname: method
pairs". It does show a space after the colon in the examples it gives, but the CF Compliance checker is happy with no space after the colon.Unit tests have been updated to test that:
cell_method
raises a warning; e.g. name but no method, such ascell_method='time'
cell_method='time:mean'
Tested on Iris version 3.10.0.dev96.
Add any of the below labels to trigger actions on this PR:
cell_methods
is not valid #6082