Skip to content

fix(query): normalize NaN cells to None in query_files_by_selector - #21

Merged
romer8 merged 1 commit into
mainfrom
fix/normalize-nan-cells
May 21, 2026
Merged

fix(query): normalize NaN cells to None in query_files_by_selector#21
romer8 merged 1 commit into
mainfrom
fix/normalize-nan-cells

Conversation

@romer8

@romer8 romer8 commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • logic.py:649: wrap df.to_dict(orient="records") in [_normalize_record(r) for r in ...] so NaN cells become None before envelope serialization
  • New round-trip test asserting envelope passes strict json.dumps(allow_nan=False)

Why

df.to_dict(orient="records") preserves pandas NaN as float("nan"), which Python's default json.dumps(allow_nan=True) emits as the literal token NaN — not valid JSON. JS clients that JSON.parse the result silently fall through to a raw-string path.

In chatbox-core that bypasses both _engine_dispatched and _cache_uri injection: engine/index.js:1060 gates the injection block on typeof toolResult === "object", which is false for strings. Affected every hydrology query result that touched the troute nudge column on a non-assimilated reach.

The sibling code path at logic.py:754 already applied _normalize_record for the same reason. This brings line 649 in line.

Test plan

  • New test test_nan_cells_serialize_to_valid_json round-trips the envelope through json.loads(json.dumps(..., allow_nan=False))
  • 174/174 nrds_mcps tests pass locally

df.to_dict(orient="records") preserves pandas NaN as float("nan"), which
Python's default json.dumps(allow_nan=True) emits as the literal token
"NaN" — not valid JSON. JS clients that JSON.parse the result silently
fall through to a raw-string path. In chatbox-core that bypasses both
_engine_dispatched and _cache_uri injection (engine/index.js:1060
gates on isObjResult, which is false for strings). Affected every
hydrology query result that touched the troute "nudge" column on a
non-assimilated reach.

The sibling code path at logic.py:754 already applied _normalize_record
for the same reason. This brings line 649 in line with it.
@romer8
romer8 merged commit 5954fce into main May 21, 2026
2 checks passed
@romer8
romer8 deleted the fix/normalize-nan-cells branch May 21, 2026 02:41
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