fix: compare dataset versions numerically when selecting latest#739
Merged
Conversation
"Latest version" selection compared version strings with pandas `.max()`, which is lexicographic, so `"v2" > "v10"` and `"v9" > "v10"`. Datasets using the `vN` version form selected the wrong (older) version as latest/parent/supplementary. This was latent for the zero-padded `vYYYYMMDD` form but wrong for any `vN` archive. Add a `version_sort_key` helper that compares the integer after the leading `v`, and a `select_latest_version` helper that keeps the numerically-latest rows (optionally per group), both in `climate-ref-core`. Route all four selection sites through it: `DatasetAdapter.filter_latest_versions`, the `AddSupplementaryDataset` and `AddParentDataset` constraints, and the ESGF registry's `fetch_datasets`.
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 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.
Description
"Latest version" selection compared version strings with pandas
.max(), which is lexicographic — so"v2" > "v10"and"v9" > "v10". For datasets using thevNversion form, the wrong (older) version was chosen as latest/parent/supplementary. This was latent for the zero-paddedvYYYYMMDDform (where lexicographic order happens to match chronological order) but incorrect for anyvNarchive, and for thev0extraction fallback mixing with real versions.This adds two helpers to
climate-ref-core:version_sort_key, which compares the integer value after the leadingv(sov10>v2, whilevYYYYMMDDforms still order chronologically), andselect_latest_version, which keeps the numerically-latest rows, optionally per dataset group. All four version-selection sites now route through these instead of string.max():DatasetAdapter.filter_latest_versions, theAddSupplementaryDatasetandAddParentDatasetconstraints, and the ESGF registry'sfetch_datasets(a fourth site that carried the same bug).Behaviour is unchanged for the common
vYYYYMMDDdatasets; onlyvN-form selection changes (now correct). Verified withmypy,ruff, and the unit suites for the helpers,filter_latest_versions, the constraints, and the ESGF registry.Checklist
Please confirm that this pull request has done the following:
changelog/