Skip to content

gh-149259: Fix median_grouped() exception chaining and error messages#149260

Closed
htjworld wants to merge 1 commit intopython:mainfrom
htjworld:fix-median-grouped-exception-chaining
Closed

gh-149259: Fix median_grouped() exception chaining and error messages#149260
htjworld wants to merge 1 commit intopython:mainfrom
htjworld:fix-median-grouped-exception-chaining

Conversation

@htjworld
Copy link
Copy Markdown
Contributor

@htjworld htjworld commented May 2, 2026

Closes #149259.

median_grouped() placed both float conversions in a single try block
with no from exc chaining, so the original ValueError was silently
discarded and the message gave no clue which argument failed.

  • Split into two try blocks so interval and data failures are
    reported separately.
  • Add from exc so the original ValueError appears in tracebacks.
  • Improve messages: interval must be a real number, got 'bad' vs
    data sequence must contain real numbers, found 'b'.

No behaviour change for callers (still TypeError in the same cases).
A new test test_exception_chaining_and_messages verifies the chain
and message content.

…ssages

Split the single try/except block into two, add `from exc` chaining so
the original ValueError is visible in tracebacks, and improve the error
messages to identify whether `interval` or the data value failed the
float conversion.
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32506004 | 📁 Comparing 20c7ecb against main (ff35fe4)

  🔍 Preview build  

30 files changed · ± 30 modified

± Modified

@rhettinger rhettinger self-assigned this May 2, 2026
@rhettinger rhettinger closed this May 2, 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: median_grouped() loses exception context when converting interval

2 participants