Skip to content

skip empty summaries in AggregateSummaryStatistics.aggregate - #354

Merged
aherbert merged 1 commit into
apache:masterfrom
insaf021:aggregate-skip-empty-summaries
Nov 14, 2026
Merged

aherbert merged 1 commit into
apache:masterfrom
insaf021:aggregate-skip-empty-summaries

Conversation

@insaf021

Copy link
Copy Markdown
Contributor

On master, with SummaryStatistics partitions:

aggregate([{1, 2}, {3}])      n=3 min=1.0 max=3.0 mean=2.0 variance=1.0 sum=6.0
aggregate([{1, 2}, {}, {3}])  n=3 min=NaN max=NaN mean=NaN variance=NaN sum=NaN

SummaryStatistics reports NaN for every statistic while it holds no values, and AggregateSummaryStatistics.aggregate folds each summary in unconditionally: JdkMath.min/max propagate the NaN, and the sum, mean and second moment pick it up through the running totals. One empty partition anywhere in the collection therefore wipes out the combined result, although the javadoc says it should match a single summary over the combined data. Empty partitions are routine when work is split across threads or groups. The NaN-tolerant min/max removed in MATH-1671 masked part of this; the variance was already lost before that.

Summaries with getN() == 0 are now skipped, both when picking the starting summary and in the accumulation loop, and the javadoc says so. An all-empty collection still returns n = 0 with NaN statistics, as before.

AggregateSummaryStatisticsTest.testAggregateEmptySummaries puts empty partitions at the start, middle and end. On master it fails with expected:<5.0> but was:<NaN>; it passes with the patch. mvn clean verify javadoc:javadoc -pl commons-math-legacy -am is green on JDK 21 (3264 tests in legacy, Checkstyle and SpotBugs clean).

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.21%. Comparing base (f554608) to head (abe2aa0).
⚠️ Report is 418 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #354      +/-   ##
============================================
+ Coverage     86.54%   87.21%   +0.66%     
+ Complexity     9787       91    -9696     
============================================
  Files           532      499      -33     
  Lines         35516    33538    -1978     
  Branches       6194     5855     -339     
============================================
- Hits          30738    29250    -1488     
+ Misses         3518     3164     -354     
+ Partials       1260     1124     -136     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aherbert
aherbert merged commit 8acd0e7 into apache:master Nov 14, 2026
12 checks passed
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.

3 participants