Repository navigation
fix(scores): coerce numpy and Decimal score values to float in create_score - #2058
lalith0407 wants to merge 1 commit into
Conversation
|
|
|
|
||
|
|
||
| def test_create_score_sends_numpy_values_as_numbers(client_factory): | ||
| np = pytest.importorskip("numpy") |
There was a problem hiding this comment.
The new test uses pytest.importorskip("numpy"), but numpy is absent from the declared dependencies and uv.lock. CI installs those locked dependencies, so it never checks the NumPy cases that motivated this fix. Install NumPy in at least one test job and run this test there.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/test_score_consumer.py
Line: 817
Comment:
**CI skips the NumPy test**
The new test uses `pytest.importorskip("numpy")`, but `numpy` is absent from the declared dependencies and `uv.lock`. CI installs those locked dependencies, so it never checks the NumPy cases that motivated this fix. Install NumPy in at least one test job and run this test there.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
chrikrah
left a comment
There was a problem hiding this comment.
@lalith0407 From my perspective this can be merged at 0cda483. #2006 promised the queued values would match CreateScoreRequest, and its parity test says so by name, but the merged code converted only bool and int. This closes that gap for span.score, score_trace and the batch evaluator as well, since they all call create_score.
$ pytest tests/unit/test_score_consumer.py -q -p no:cacheprovider # Python 3.12, numpy 2.5.4 installed by hand
38 passed, 1 skipped in 4.87s # 0cda483 (skip: gevent not installed)
2 failed, 36 passed, 1 skipped in 4.79s # client.py from ab861f1, tests kept
non-blocking: I agree with the bot's note on line 817. numpy isn't in uv.lock, so CI skips the numpy test. Should numpy go in the dev group so CI runs it?
HUMAN
While scoring with numpy-based evaluators, I noticed that since #2006 a
numpy.bool_score is sent as JSONtrueand aDecimalas the string"<Decimal>", because the new hand-built request only convertsboolandint. I restored the old behavior of converting any numeric value to float, and extended the existing parity test with Decimal, Fraction and numpy cases.What does this PR do?
Fixes #2057. Before #2006 every non-str score value went through
CreateScoreRequest, which coerced it to float. The hand-built body only coercesbool/int, sonumpy.bool_is sent astrue(rejected by the API'sstring | numberschema) andDecimalas"<Decimal>"(stored as a categorical string). Now any non-str, non-float value thatfloat()accepts is converted. Anything else passes through unchanged, as on main.Type of change
Verification
numpy.bool_(True)true1.0Decimal("0.75")"<Decimal>"0.75numpy.int64(3)33.0(matches v5.0.1)True,0.5,"good"test_create_score_payload_matches_request_model_serializationnow includesDecimalandFractioncases. It fails on main and passes here.test_create_score_sends_numpy_values_as_numbers(skips if numpy isn't installed). It fails on main and passes here.pytest tests/unit: 955 passed. The 18test_prompt.pyerrors also happen on unchanged main without LANGFUSE_* env vars.ruff check,ruff format --check, andmypy langfuseare clean.The fix appears safe to merge, with a non-blocking gap in NumPy test coverage.
Summary
create_scorenow converts values such as Decimal, Fraction, and NumPy scalars to floats while leaving strings and existing floats unchanged.Reviews (1) · Last reviewed commit: "fix(scores): coerce numpy and Decimal sc..." · Reviewed by Greptile