Skip to content

refactor(eval): one mean_in_range, in eval/stats - #1642

Open
napetrov wants to merge 6 commits into
intel:mainfrom
napetrov:arch/r12-6
Open

napetrov wants to merge 6 commits into
intel:mainfrom
napetrov:arch/r12-6

Conversation

@napetrov

@napetrov napetrov commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Summary

before: eval/arm_summary.mean_in_range   eval/stats._mean
                 \___ same body ___/
after:  eval/stats.mean_in_range  <-  arm_summary, report/eval_report
        context/consistency: stats_mean = mean_in_range

mean_in_range (arm_summary) and _mean (stats) carried the same body: the plain mean, or statistics.mean when the sum of finite values leaves the float range. One public mean_in_range now lives in eval/stats.py; arm_summary and report/eval_report import it from there; context/consistency keeps its stats_mean alias.

Evidence

  • Differential probe, 3015 inputs (empty, NaN, inf, -inf, overflow, random): pre-change body vs stats.mean_in_range, arm_summary name and the consistency alias: 0 diffs. Empty still raises ZeroDivisionError; NaN and inf propagate; overflow falls back to statistics.mean.
  • ruff and mypy clean on the touched modules.
  • pytest tests/: 35857 passed, 4 failed. One failure needs the mcp package, absent in the local venv. Three CLI timeouts under box load pass when rerun alone.
  • Local self-review: one fresh-context pass per commit, no blocking threads.

Merge Danger

  • Private name stats._mean is gone; only tests/test_stats.py used it, now updated. No public name is removed (arm_summary.mean_in_range still resolves via the import).
  • Import edge flips: arm_summary now imports stats. stats no longer imports arm_summary. Import cycle check passes.
  • Pure refactor, no user-visible effect: labelled skip-changelog. A second commit adds a short fragment only because the local pre-push gate cannot see labels; drop it if the label is enough for CI.

🤖 Generated with Claude Code

arm_summary.mean_in_range and stats._mean had the same body: the plain
mean, or the exact statistics.mean when the sum of finite values leaves
the float range. Keep the public mean_in_range in eval/stats.py; arm_summary
and report/eval_report import it from there, and context/consistency keeps
its stats_mean alias. Behaviour is unchanged (empty input still raises
ZeroDivisionError, NaN and inf propagate as before).

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov
napetrov requested a review from a team as a code owner December 5, 2026 05:08
Copilot AI balanced review requested due to automatic review settings December 5, 2026 05:08
@napetrov napetrov added the skip-changelog No user-visible change: bypasses the changelog fragment check label Dec 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable issues were found in the reviewed changes.

No open issues 🎉

What changed in this PR

0 new findings; nothing to fix.

This refactor consolidates dokimi’s overflow-safe mean calculation in eval.stats.mean_in_range, preserving existing behavior.

Changes:

  • Removes the duplicate helper and updates callers while preserving existing aliases.
  • Updates numerical regression tests to use the public name.
  • Adds a changelog fragment documenting the private-name migration.
File Description
dokimi/​tests/​test_stats.py Updates overflow tests to call mean_in_range.
dokimi/​dokimi/​report/​eval_report.py Imports the helper directly from stats.
dokimi/​dokimi/​eval/​stats.py Defines the shared helper and updates internal calls.
dokimi/​dokimi/​eval/​arm_summary.py Replaces the duplicate implementation with an import.
dokimi/​dokimi/​context/​consistency.py Preserves stats_mean using the renamed helper.
dokimi/​changelog.d/​20261205_050000_napetrov_r12-6-mean-in-range.md Documents consolidation and migration from _mean.

Review effort: Balanced

@exai-bot

exai-bot commented Dec 5, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 7 selected item(s).

CI at 0aa5973: 21 passing, 4 skipped.

Review details
  • Commit reviewed: 0aa5973 against merge base 60948d0
  • Coverage: 7 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 71k tokens (42k from cache), 9s
  • Tool calls: 10 (6 file_read, 2 code_search, 1 ci_status, 1 local_check_results)
  • Mean-in-range evaluation statistics, consistency, reporting, and tests: 7 files

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 2 of 30 small breaks of the lines this PR changes

At 0aa5973: 28 caught · 2 missed

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/eval/stats.py:393 drop-clause math.isfinite(mu) or not all(math.isfinite(v) for v in values) → (math.isfinite(mu)) 397
dokimi/dokimi/eval/stats.py:188 drop-clause finite and not math.isfinite(mean) → (finite) 99

Not checked:

  • 1 changed line was not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

@codecov-commenter

codecov-commenter commented Dec 5, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.44%. Comparing base (60948d0) to head (0aa5973).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1642      +/-   ##
==========================================
- Coverage   96.45%   96.44%   -0.01%     
==========================================
  Files         575      575              
  Lines       75872    75866       -6     
  Branches    13076    13075       -1     
==========================================
- Hits        73179    73166      -13     
- Misses       1644     1646       +2     
- Partials     1049     1054       +5     
Files with missing lines Coverage Δ
dokimi/dokimi/context/consistency.py 98.16% <100.00%> (ø)
dokimi/dokimi/eval/arm_summary.py 100.00% <100.00%> (ø)
dokimi/dokimi/eval/stats.py 97.95% <100.00%> (-0.01%) ⬇️
dokimi/dokimi/report/eval_report.py 95.71% <100.00%> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at f1a6fb7. The change itself reads right: the two bodies were identical, the merge into eval/stats.py is clean, and no caller or doc still names _mean. One possible issue for the author to check before merge, which I could not settle.

Possible issue: tests fail with this PR merged into main. I merged the PR into today's main (4deffc0) on a Linux review host and ran the tests. These failed there, and I did not see them fail on main alone:

  • tests/test_check_test_timing.py::test_the_repo_tree_holds_its_own_baseline
  • tests/test_novelty_routing_all_vs_all.py::test_an_unreadable_queries_file_is_a_message_not_a_traceback[missing]
  • tests/test_repo_runner.py::test_run_refuses_a_budget_that_caps_nothing[inf]
  • tests/test_repo_typecheck_grader.py::test_the_subjects_mypy_ini_cannot_suppress_a_listed_file
  • two more with a 60s timeout or a gc-callback warning

Most of these look like load on a small host and unrelated to a rename. The first one may be real: removing the duplicate _mean can shrink a recorded baseline, and the repo asks for python scripts/check_growth.py --update after a shrink. Please run these tests on the merge and lower the baseline if it is that.

What I ran, on a Linux review host at f1a6fb7:

  • make ci-local: 36 passed, 2 failed. Run tests had 35,859 passed and 4 failed (timeouts and gc-callback warnings in test_cli_model_ref.py and test_fuzz_targets.py, which pass when rerun alone). pip-audit failed on a read timeout reaching pypi.org, not on an advisory.
  • Imported arm_summary then stats in a fresh interpreter: no import cycle, and arm_summary.mean_in_range is stats.mean_in_range.

Checked, no issues

  • Callers: a grep finds no remaining stats._mean or arm_summary.mean_in_range use.
  • Behaviour: the moved body is the old stats._mean with the parameter renamed.
  • Process: both commits carry Signed-off-by, and skip-changelog is on the PR.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by antonwolfy

Please run these tests on the merge and lower the baseline if it is that.
All four named tests passed with both 4deffc04 and current main merged in. The growth check passed on both merges. Neither mean-helper module has a growth baseline entry.

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@napetrov, could you fix the problem I found (in the line comments)? Then push and I'll take another look.

Optional, non-blocking (1)
  • dokimi/dokimi/eval/stats.py:188: With an infinity in values, an overflowing resample gives inf at eval/stats.py:188, and using the exact mean there still passes tests/test_stats.py.

What I checked on 85fbe48:

  • When I changed the code on purpose, the tests still passed for 1 of 6 changes, and no test pins this one down yet (non-blocking): dokimi/dokimi/eval/stats.py:531 (it returns None).
  • The 92 changed tests pass, and pass on main too.
  • The full test suite passes with main merged in (37,836 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/tests/test_stats.py Resolved
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AMogM
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRR_kwDOVBg7g88AAAABcfGTxQ.a
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vchamarthi

Optional bootstrap and PairedSummary mutation checks
0aa59736b pins bootstrap. paired_summary returning None fails 15 tests.

@napetrov

napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

The ordinary-mean regression test now catches the or to and change for [0.1, 0.2, 0.3]. The float-range case also catches changing the overflow policy for a bootstrap input containing infinity. Both pass on the production code. PairedSummary returning None fails existing tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog No user-visible change: bypasses the changelog fragment check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants