Skip to content

fix(results): project NumPy scalar measurements as plain JSON values - #796

Closed
Abhishek-B-R wants to merge 1 commit into
Hebbian-Robotics:mainfrom
Abhishek-B-R:fix/result-projection-numpy
Closed

Abhishek-B-R wants to merge 1 commit into
Hebbian-Robotics:mainfrom
Abhishek-B-R:fix/result-projection-numpy

Conversation

@Abhishek-B-R

@Abhishek-B-R Abhishek-B-R commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

project_results now accepts measurements a check returned as NumPy scalars. Before, selecting a measurement whose value was np.float64(0.5) or np.int64(3) raised ValueError: selected measurement is not a finite JSON scalar, even though the value is finite and the catalog stores it as 0.5 / 3.

Why

MeasuredCheck.__post_init__ checks type(value) not in (str, bool, int, float). That exact type test refuses every NumPy scalar, np.float64 included, which is what a check gets from almost any NumPy reduction. The catalog boundary converts these with .item() (#126), so the same report records fine and only fails when it is projected for an external consumer.

Repro:

@app.check(version="1")
async def c(ep):
    return hflow.CheckResult(measurements={"ratio": np.float64(0.5)})

report = asyncio.run(app.test(episode_path, verbose=False))
project_results(report, (CheckSelection("c", "quality", {"ratio": "ratio"}),))
# ValueError: selected measurement is not a finite JSON scalar

MeasuredCheck now converts np.generic values with .item() before the existing checks, so the payload still holds only plain str, bool, int and float, and a NumPy NaN is still refused as non-finite.

Validation

  • New test_result_projection_accepts_numpy_scalar_measurements in tests/test_result_projection.py: fails on main with the ValueError above, passes with the fix. It also checks that np.float32("nan") is still refused.
  • uv run pytest -q tests/test_result_projection.py: 5 passed.
  • pytest -q -n 4 in the uv sync --locked environment (macOS, Python 3.11): 2598 passed, 49 skipped.
  • uv run ruff check, uv run ruff format --check, uv run ty check: clean.

Checklist

  • I added or updated outcome-focused tests for changed business logic.
  • I updated documentation for changed behavior, flags, formats, or requirements. (No documented behavior changes.)
  • I ran uv run ruff check --fix, uv run ruff format, and uv run ty check.
  • I ran the relevant pytest suite.
  • I did not add recordings, generated media, credentials, private URLs, or runtime artifacts.
  • I preserved stored-data compatibility or documented an explicit version change.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

MeasuredCheck accepted a measurement only when its type was exactly
str, bool, int or float, so project_results raised "selected measurement
is not a finite JSON scalar" for a check that returned np.float64(0.5)
or np.int64(3), values the catalog stores without complaint. NumPy
scalars are now converted with .item() first, the same way the catalog
does, and the existing type and finiteness checks run on the result.
@github-actions

Copy link
Copy Markdown

👋 Hi @Abhishek-B-R — thanks for the contribution! To keep starter issues available
for other contributors and give every pull request a real review, we accept
1 open pull request per contributor at a time.

You already have #795 open, so this one is being closed automatically.
Once your open pull request is merged or closed, feel free to reopen this one —
no work is lost.

@github-actions github-actions Bot closed this Nov 17, 2026
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

MeasuredCheck now converts NumPy scalar measurements with .item() before checking them.

  • Result projections turn NumPy measurements into plain JSON values.

Reviews (1) · Last reviewed commit: "fix(results): project NumPy scalar measu..." · Reviewed by Greptile

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