Skip to content

fix: JSON reports emit invalid NaN + O(n) rolling window#6

Merged
stef41 merged 1 commit intomainfrom
fix/json-nan-and-rolling-window-perf
Apr 11, 2026
Merged

fix: JSON reports emit invalid NaN + O(n) rolling window#6
stef41 merged 1 commit intomainfrom
fix/json-nan-and-rolling-window-perf

Conversation

@stef41
Copy link
Copy Markdown
Owner

@stef41 stef41 commented Apr 11, 2026

Bug: Invalid JSON output

When NaN detector fires, save_json() emits bare NaN literals — invalid per RFC 8259. Every non-Python JSON parser (JS, jq, Go, Rust) rejects the file.

Fix: Sanitize NaN/Inf to null in report_to_dict().

Performance: RollingWindow

list.pop(0) is O(n) — shifts all elements on every training step. Replaced with collections.deque(maxlen=N) for O(1) append.

Tests

All 220 tests pass.

- report_to_dict now sanitizes NaN/Inf metric_value to null, producing
  RFC 8259-compliant JSON readable by any parser (not just CPython).
- RollingWindow uses collections.deque(maxlen=N) instead of list with
  pop(0), reducing per-step cost from O(window_size) to O(1).
@stef41 stef41 merged commit f05e37a into main Apr 11, 2026
5 checks passed
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