Skip to content

Accept one-cent differences in --check-results and warn on inexact matches - #66

Merged
sambles merged 2 commits into
mainfrom
tests/cent-tolerance-and-tolerance-warning
Nov 24, 2026
Merged

sambles merged 2 commits into
mainfrom
tests/cent-tolerance-and-tolerance-warning

Conversation

@benhayes21

@benhayes21 benhayes21 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

For OasisLMF/OasisLMF#2244

Problem

--check-results compares numeric values with a 1e-4 relative tolerance. Losses are written to 2 decimal places, so a loss that sits on a half-cent boundary can round either way when the float summation order changes. For small losses, that one-cent flip exceeds the tolerance.

OasisLMF#2244 hits this in PiWindPostcode/test_3. CI runners produce two different il_S1_selt.csv outputs for the same code, most likely because of different CPU types:

output runners event 880, sample 5
A py3.10, 3.13, 3.14 (run 1) and local 22.88
B py3.12 (run 1), py3.11 (run 2) 22.87

The true loss is about 22.875. A and B fail against each other, so no single baseline can pass on every runner: rebaselining would only change which runners fail.

Change

  • Tolerance: a numeric value now passes if it is within the relative tolerance or within one cent (_NUMERIC_ABS_TOL, plus a 1e-9 epsilon because 22.88 - 22.87 > 0.01 in float64). The byte comparison and the relative tolerance are unchanged. The cent only widens the check for values below about 100, where 1e-4 relative is less than the printed precision.
  • Warning: files that are not byte-identical but are within tolerance used to pass silently. They now raise a ResultsWithinToleranceWarning, which appears in pytest's warnings summary. It lists each file with the number of differing values and the largest difference per column, e.g.
    il_S1_selt.csv (Loss: 88 value(s) differ, max abs diff 0.05)
    

No expected results change, so this PR does not need to merge in step with OasisLMF#2244.

Testing

Ran apply_results_flags from this branch against the PiWindPostcode/test_3 outputs from the OasisLMF#2244 CI artifacts, with the current expected_results:

  • outputs A and B both pass and raise the warning (both previously: A passed, B failed);
  • an output identical to the baseline passes with no warning;
  • adding 0.02 to the 22.88 loss still fails.

End to end: the OasisLMF model-test workflow on OasisLMF#2244 against this branch (run 44325924556) passes on all five Python versions (22 passed, 5 skipped). It raises the warning for 19 of the 22 tests: #2244 renumbers items, so most outputs move within tolerance. Rebaselining after #2244 merges would make them byte-identical again on at least one runner type.

🤖 Generated with Claude Code

…tches

Losses are written to 2 decimal places, so a loss on a half-cent boundary can
round either way when the float summation order changes, e.g. between the CPU
types of CI runners. For small losses a one-cent flip exceeds the 1e-4 relative
tolerance (22.88 vs 22.87 is 4.4e-4), so no single baseline passes on every
runner. A numeric value now passes if it is within the relative tolerance or
within one cent.

Files that pass within tolerance but are not byte-identical are no longer
passed silently: they are reported in a ResultsWithinToleranceWarning, with the
number of differing values and the largest difference per column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve import conflict in tests/conftest.py: keep pytest_plugins from #31
and the numpy import from this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@benhayes21

Copy link
Copy Markdown
Contributor Author

This PR has no cross-repo dependency: it changes no baselines and passes against OasisLMF main. It can merge before #67 and OasisLMF/OasisLMF#2244. Merging it first means a dispatched run of #2244 against #67 (rebased) should be fully green, including PiWindPostcode/test_3. See the merge-order note on #67.

@sambles
sambles merged commit a979eb3 into main Nov 24, 2026
4 of 8 checks passed
@sambles
sambles deleted the tests/cent-tolerance-and-tolerance-warning branch November 24, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants