Skip to content

gh-131723: Support compatible Decimal inputs in weighted fmean - #159835

Closed
limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-131723-fmean-decimal-weights
Closed

limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-131723-fmean-decimal-weights

Conversation

@limadog9

@limadog9 limadog9 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Weighted fmean() currently divides a Decimal numerator by a float denominator, raising TypeError even when the data and weights have compatible types. Convert the numerator to float before division so these inputs produce the documented float result.

Following the approach suggested in the issue, clarify in the documentation and docstring that weighted inputs must support multiplication with each other. Mixed Decimal/float and Decimal/Fraction inputs remain unsupported. Add regression coverage for Decimal data, Decimal weights, and both together.

Fixes #131723.

Validation:

  • All statistics tests on a free-threaded debug build: 401 tests, 5 skipped. The new regression fails before the fix.
  • Full HTML documentation build with warnings treated as errors.
  • Ruff, Sphinx lint, and patchcheck.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35258461 | 📁 Comparing 5d47741 against main (0fba211)

  🔍 Preview build  

2 files changed
± library/statistics.html
± whatsnew/changelog.html

@limadog9
limadog9 force-pushed the gh-131723-fmean-decimal-weights branch from 5d47741 to e2b21cf Compare October 20, 2026 12:50
@limadog9 limadog9 closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

statistics.fmean() does not support Decimal data, contrary to documentation

1 participant