Skip to content

Keep avg finite when intermediate sum overflows - #386

Open
AryanRG wants to merge 1 commit into
jmespath:developfrom
AryanRG:fix/avg-finite-overflow
Open

AryanRG wants to merge 1 commit into
jmespath:developfrom
AryanRG:fix/avg-finite-overflow

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown

Summary

avg(@) can return infinity for finite inputs when their sum overflows even though the average is representable. For example:

import jmespath

assert jmespath.search("avg(@)", [1e308, 1e308]) == 1e308

The current result is inf. This change uses an overflow-safe fallback for that case while preserving the existing calculation for ordinary inputs. Regression tests cover large positive and negative values, cancellation, and controls.

Validation

  • New regression on the base: 1 failed, 6 controls passed.
  • Patched full suite: 993 passed, 1 skipped on both Python 3.9.6 and 3.14.4.
  • Lint and git diff --check: passed.

The full suite was not run on other Python versions or platforms; hosted CI remains to be checked.

AI assistance was used to prepare the implementation and regression tests.

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.

1 participant