Skip to content

Return null from avg of an empty array - #103

Open
SashaMIT wants to merge 1 commit into
jmespath:masterfrom
SashaMIT:fix/avg-empty-array
Open

SashaMIT wants to merge 1 commit into
jmespath:masterfrom
SashaMIT:fix/avg-empty-array

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 2, 2026 •

Copy link
Copy Markdown

Summary

  • avg of an empty array returned NaN. The sum is 0 and the length is 0, so the division is 0/0.
  • The spec says an empty array produces null. max and min of an empty array already return null. avg([]) now does too.
  • avg of [-1, 3, 4, 5] is still 2.75.

Test plan

  • go test -count=1 .
  • avg(empty_list) failed on master (float64(NaN), expected nil) and passes after the change.

The spec says an empty array is null. The zero sum divided by zero
was NaN.
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