1"""Non-finite floats must not take down an API response.
3A NaN anywhere in the results dict made json.dumps raise
4"Out of range float values are not JSON compliant", which the evaluate router
5turned into a blanket HTTP 500 on forward evaluation. NaN is a legal model output
6(e.g. a lag model that does not define K_v), so it must serialise as null.
18 pytest.param(ev_convert, id=
"evaluate"),
19 pytest.param(fl_convert, id=
"flight"),
20 pytest.param(ts_convert, id=
"timeseries"),
21 pytest.param(op_convert, id=
"optimizer"),
25@pytest.mark.parametrize("convert", CONVERTERS)
26@pytest.mark.parametrize("bad", [float("nan"), float(
"inf"), float(
"-inf"),
27 np.float64(
"nan"), np.float64(
"inf")])
32@pytest.mark.parametrize("convert", CONVERTERS)
34 """The shape that actually broke: NaN buried in the stability payload."""
37 "F": np.float64(8000.0),
38 "stability_rich": {
"chug": {
"lag_breakdown": {
39 "O": {
"K_v": float(
"nan"),
"tau_vap_s": 0.0037},
40 "F": {
"K_v": np.float64(
"nan"),
"tau_vap_s": 0.0141},
42 "series": [1.0, float(
"inf"), np.float64(
"nan"), 4.0],
46 assert out[
"stability_rich"][
"chug"][
"lag_breakdown"][
"O"][
"K_v"]
is None
47 assert out[
"stability_rich"][
"chug"][
"lag_breakdown"][
"F"][
"K_v"]
is None
48 assert out[
"series"][1]
is None and out[
"series"][2]
is None
51@pytest.mark.parametrize("convert", CONVERTERS)
53 """The guard must not eat real numbers."""
54 assert convert(np.float64(8000.0)) == pytest.approx(8000.0)
56 assert convert(-1.5) == pytest.approx(-1.5)
57 assert convert(np.int64(26)) == 26
json_pointer< string_t > convert() const &
test_finite_values_are_untouched(convert)
test_nested_payload_is_json_serialisable(convert)
test_non_finite_becomes_none(convert, bad)