Skip to content

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

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

statistics: Fix geometric_mean() error message for negative inputs#149246
rhettinger merged 2 commits intopython:mainfrom
htjworld:fix-geometric-mean-error-message

Conversation

@htjworld
Copy link
Copy Markdown
Contributor

@htjworld htjworld commented May 1, 2026

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
Copy link
Copy Markdown

bedevere-app Bot commented May 1, 2026

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.

@skirpichev
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 htjworld force-pushed the fix-geometric-mean-error-message branch from 4375281 to 7eed882 Compare May 1, 2026 18:45
@htjworld
Copy link
Copy Markdown
Contributor Author

htjworld commented May 1, 2026

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 rhettinger self-assigned this May 1, 2026
@skirpichev
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 rhettinger merged commit 0f5cd57 into python:main May 2, 2026
48 checks passed
@rhettinger
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.

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