feat: guard CMORisation against missing input files#554
Merged
Conversation
Add filename-based completeness check to file discovery: - Add `_extract_year_month_from_path()` that returns (year, month) or (year, None) for all known ACCESS filename conventions. - Add `MissingInputFilesError(FileDiscoveryError)` with a `.missing` attribute listing the absent (year, month) slots. - Add public `check_file_completeness(paths, freq)` that inspects filenames only (no file I/O) and returns missing monthly or annual slots. Works for all sub-annual frequencies (mon, day, 3hr, 6hr, 1hr) via YYYYMM filename parsing, and falls back to annual checking for yr or ocean annual files. - Add `check_completeness=False` parameter to `discover_files()`: when True, raises `MissingInputFilesError` before any file I/O if expected monthly/yearly files are absent. fx fields are exempt. - Export new symbols from `__all__`. - Add 20 unit tests covering all new code paths.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #554 +/- ##
=======================================
+ Coverage 74.3% 74.5% +0.1%
=======================================
Files 36 36
Lines 7274 7343 +69
Branches 1354 1373 +19
=======================================
+ Hits 5408 5470 +62
- Misses 1581 1584 +3
- Partials 285 289 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Add a filename-based completeness check to
file_discoveryso that missingmonthly (or yearly) raw output files are caught before any file I/O or
CMORisation begins.
Changes
src/access_moppy/file_discovery.py_extract_year_month_from_path(path)— extends the year parser to also returnthe month, covering all known ACCESS filename conventions.
MissingInputFilesError(FileDiscoveryError)— new exception with a.missinglist of
(year, month)tuples.check_file_completeness(paths, freq)— public, filename-only function thatreturns missing monthly or annual slots. Works for all sub-annual frequencies
(mon, day, 3hr, 6hr, 1hr) and falls back to annual for
yr/ ocean files.discover_files(..., check_completeness=False)— whenTrue, raisesMissingInputFilesErrorbefore any file I/O.fxfields are exempt.tests/unit/test_file_discovery.pyUsage