Skip to content

fix(aggregations): guard mean_of_measurement against empty measurements - #1608

Open
WatchTree-19 wants to merge 1 commit into
mlcommons:mainfrom
WatchTree-19:fix-mean-of-measurement-empty
Open

fix(aggregations): guard mean_of_measurement against empty measurements#1608
WatchTree-19 wants to merge 1 commit into
mlcommons:mainfrom
WatchTree-19:fix-mean-of-measurement-empty

Conversation

@WatchTree-19

Copy link
Copy Markdown
Contributor

what

mean_of_measurement divides by len(measurements) with no empty guard:

measurements = get_measurements(measurement_name, items)
total = sum(measurements)
return total / len(measurements)

so a test whose aggregate_measurements() receives no measured items - e.g. every item errored or was filtered out - raises ZeroDivisionError instead of producing a score, crashing aggregation/reporting.

its sibling in the same module, MeasurementStats.calculate, already guards this and returns mean 0 for an empty input. mean_of_measurement now does the same, keeping the two consistent.

fix

return 0.0 when there are no measurements. adds regression tests (test_mean_of_measurement and test_mean_of_measurement_no_measurements) - the empty case raises ZeroDivisionError on main and passes with the change. black clean, DCO signed.

mean_of_measurement divided by len(measurements) with no empty guard, so a test
whose aggregate_measurements() receives no measured items (e.g. every item
errored or was filtered) raised ZeroDivisionError instead of producing a score.
Its sibling MeasurementStats.calculate already returns mean 0 for an empty input;
mean_of_measurement now does the same. Adds regression tests.

Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
@WatchTree-19
WatchTree-19 requested a review from a team as a code owner August 10, 2026 20:56
@WatchTree-19
WatchTree-19 deployed to Scheduled Testing August 10, 2026 20:56 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could an empty set remain distinguishable from a measured zero? Returning 0.0 means an all-error or all-filtered run becomes a valid zero measurement. For safety benchmarks that can make missing coverage look benign and bias aggregates. I would prefer NaN / None, or an explicit no-data result, rather than converting absence of evidence into a score.

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.

2 participants