FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

statistics: Fix geometric_mean() error message for negative inputs by htjworld · Pull Request #149246 · python/cpython · GitHub

Repository navigation

statistics: Fix geometric_mean() error message for negative inputs - #149246

Merged
rhettinger merged 2 commits into
python:mainfrom
htjworld:fix-geometric-mean-error-message
May 2, 2026
Merged

rhettinger merged 2 commits into
python:mainfrom
htjworld:fix-geometric-mean-error-message

Conversation

htjworld commented May 1, 2026

Copy link
Copy Markdown
Contributor

geometric_mean() raised StatisticsError with two positional arguments,
causing str(e) to display as a tuple:

('No negative inputs allowed', -2.0)

Every other StatisticsError in the module uses a single string message.
Replaced with an f-string so the message reads:

No negative inputs allowed: -2.0

bedevere-app Bot commented May 1, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Copy Markdown
Member

Test failures are unrelated. BTW, I think this small fix is fine for backports (issue valid for v3.13).

The error message was constructed with two positional arguments to
StatisticsError, causing str(e) to display as a tuple:
"('No negative inputs allowed', -2.0)". Use an f-string instead so
the value is embedded directly in the message string.
htjworld force-pushed the fix-geometric-mean-error-message branch from 4375281 to 7eed882 Compare May 1, 2026 18:45

htjworld commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review!
I have rebased the branch on top of the latest upstream/main to refresh the CI. Happy to backport to 3.13 if needed.

rhettinger self-assigned this May 1, 2026

Copy link
Copy Markdown
Member

In order to keep the commit history intact, please avoid squashing or amending history and then force-pushing to the PR. Reviewers often want to look at individual commits. When the PR is merged, everything will be squashed into a single commit.

rhettinger merged commit 0f5cd57 into python:main May 2, 2026
48 checks passed

Copy link
Copy Markdown
Contributor

Let's not backport this. Besides being a minor edit, it wasn't actually wrong. We sometimes to supply the value object as the last element of the tuple so that a user can extract it.

In this particular case, I approved the edit because the result looks nice and because the tuple with value style is not used elsewhere in this module.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL