Skip to content

fix(resample): reject a non-finite to_grid rate - #729

Closed
ayam04 wants to merge 1 commit into
Hebbian-Robotics:mainfrom
ayam04:fix/to-grid-rate-guard
Closed

ayam04 wants to merge 1 commit into
Hebbian-Robotics:mainfrom
ayam04:fix/to-grid-rate-guard

Conversation

@ayam04

@ayam04 ayam04 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What changed

to_grid guarded the rate with if rate_hz <= 0.0. nan compares false against every comparison, and inf is positive, so both got past that check and reached Fraction(rate_hz) in _grid_timestamps_ns, where they surfaced as ValueError: cannot convert NaN to integer ratio and OverflowError: cannot convert Infinity to integer ratio instead of a rate error.

The rate now goes through require_finite_float from hflow._field_guards before anything else, so a non-finite rate is refused with rate_hz must be finite, got nan. The existing non-positive branch and its message are unchanged, which keeps rate_hz must be positive, got 0.0 for 0 and negative rates. The shared guard also rejects bool, which previously passed as 1 Hz.

I kept require_finite_float alongside the existing branch rather than collapsing both into require_positive_float so the message already documented for 0 and negative rates does not change. Say the word if you would rather have the uniform must be > 0 wording from the shared guard; it is a one-line change.

Tests

test_to_grid_requires_a_finite_positive_rate is parametrized over 0.0, -1.0, nan, inf and -inf, asserting the message each case has to produce. It replaces the single-case test_to_grid_rejects_nonpositive_rate.

Validation

  • pytest tests/test_resample_derive.py -q -> 23 passed
  • RED proof: with the new guard line removed, the nan, inf and -inf rows fail (3 failed, 2 passed) with cannot convert NaN to integer ratio / OverflowError / the non-positive message; restored, the test passes (5 passed)
  • ruff check + ruff format --check on both files: clean
  • ty check: clean

Fixes #726


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

to_grid guarded rate_hz with `<= 0.0`, so nan compared false and inf read as positive; both reached Fraction(rate_hz) in _grid_timestamps_ns and surfaced as "cannot convert NaN to integer ratio" and OverflowError instead of a rate error. Route the rate through require_finite_float from _field_guards first, keeping the existing non-positive branch and message unchanged.

The parametrized test covers 0, a negative rate, nan, inf and -inf, asserting the message each one must produce. Removing the guard line fails the nan/inf/-inf rows (3 failed, 2 passed); restored, 5 pass.
@greptile-apps

greptile-apps Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Summary

to_grid now rejects non-finite rates before building timestamps.

  • to_grid now rejects non-finite and boolean rates before building a grid.

Reviews (1) · Last reviewed commit: "fix(resample): reject a non-finite to_gr..." · Reviewed by Greptile

@ayam04

ayam04 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Full suite provenance, since it is not all green locally:

  • pytest -q on this branch: 2506 passed, 41 failed, 8 skipped (387s)
  • 36 of the 41 are the packaging tests (test_packaging.py 17, test_packaging_manifest_parsing.py 19), which cannot build the native overlay in this WSL image.
  • The other 5 (tests/test_cli.py x3, test_server_catalog_tables.py, test_server_episode_dossier.py) fail identically on a clean origin/main worktree (85178e7) with no changes applied: 5 failed, 25 passed. So none of the 41 are from this diff.

Nothing in the failure set touches resample, to_grid or the rate guard.

@kstonekuan

Copy link
Copy Markdown
Contributor

Closing as superseded by #728, which merged the non-finite rate fix using the shared positive-float guard.

@kstonekuan kstonekuan closed this Oct 19, 2026
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.

[Bug]: to_grid lets a NaN or infinite rate_hz past its rate check

2 participants