Skip to content

fix: compare dataset versions numerically when selecting latest#739

Merged
lewisjared merged 2 commits into
mainfrom
fix/numeric-version-selection
Jun 18, 2026
Merged

fix: compare dataset versions numerically when selecting latest#739
lewisjared merged 2 commits into
mainfrom
fix/numeric-version-selection

Conversation

@lewisjared

Copy link
Copy Markdown
Contributor

Description

"Latest version" selection compared version strings with pandas .max(), which is lexicographic — so "v2" > "v10" and "v9" > "v10". For datasets using the vN version form, the wrong (older) version was chosen as latest/parent/supplementary. This was latent for the zero-padded vYYYYMMDD form (where lexicographic order happens to match chronological order) but incorrect for any vN archive, and for the v0 extraction fallback mixing with real versions.

This adds two helpers to climate-ref-core: version_sort_key, which compares the integer value after the leading v (so v10 > v2, while vYYYYMMDD forms still order chronologically), and select_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, the AddSupplementaryDataset and AddParentDataset constraints, and the ESGF registry's fetch_datasets (a fourth site that carried the same bug).

Behaviour is unchanged for the common vYYYYMMDD datasets; only vN-form selection changes (now correct). Verified with mypy, 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:

  • Tests added
  • Documentation added (where applicable)
  • Changelog item added to changelog/

"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

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
core 92.55% <100.00%> (+0.01%) ⬆️
providers 91.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...imate-ref-core/src/climate_ref_core/constraints.py 97.67% <100.00%> (ø)
.../climate-ref-core/src/climate_ref_core/datasets.py 89.74% <100.00%> (+1.86%) ⬆️
...ate-ref-core/src/climate_ref_core/esgf/registry.py 85.55% <100.00%> (-0.16%) ⬇️
...kages/climate-ref/src/climate_ref/datasets/base.py 97.66% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lewisjared lewisjared merged commit ef9a483 into main Jun 18, 2026
27 checks passed
@lewisjared lewisjared deleted the fix/numeric-version-selection branch June 18, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant