Skip to content

Preserve arithmetic result types across mean APIs - #392

Merged
dgilland merged 2 commits into
dgilland:developfrom
Gambit-Checkmate:fix/mean-result-types
Oct 29, 2026
Merged

dgilland merged 2 commits into
dgilland:developfrom
Gambit-Checkmate:fix/mean-result-types

Conversation

@Gambit-Checkmate

Copy link
Copy Markdown
Contributor

Closes #391.

mean/mean_by/moving_mean currently annotate float results even when arithmetic returns Decimal, Fraction or complex values. Track division-by-count results with a structural SupportsMean protocol and include float for the empty-input NaN case. Int/float inputs retain their existing float inference. Propagate the same result type through moving_mean and regenerate chain declarations; runtime arithmetic is unchanged.

The new focused tests fail type checking before the fix while runtime execution already passes. They cover direct/mapping/iteratee/chained calls, Decimal/Fraction/complex, integer/float controls, empty NaN and Decimal moving windows. Three existing integer-control reveal_type snapshots were changed to assert_type only for these affected mean APIs: current mypy renders float/list[float] instead of builtins.float/builtins.list[builtins.float]. Expected types are unchanged; other snapshots were not rewritten.

Validation on Windows / CPython 3.13.13:

  • Full unit/doctest suite: 2,990 passed, 100% coverage.
  • New and existing focused mean type/execution checks: 12 passed.
  • Full source/test/tasks mypy, Ruff lint/format, generated-chain comparison and git diff checks passed.
  • Sphinx warnings-as-errors, wheel and sdist builds passed.
  • Other interpreters/platforms await hosted CI.

Unreleased changelog updated; existing AUTHORS entry retained. This complements merged #375's median correction and is separate from #261's runtime iterator fix and pending #390's reducer calls. Found through code inspection, not production use. OpenAI Codex (GPT-6 family; exact deployment identifier unavailable) assisted with investigation, implementation, tests and submission under the user's daily contribution request.

@coveralls

coveralls commented Oct 29, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — Gambit-Checkmate:fix/mean-result-types into dgilland:develop

@dgilland
dgilland merged commit 812eb13 into dgilland:develop Oct 29, 2026
5 checks passed
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.

Mean type annotations lose Decimal and other arithmetic result types

3 participants