Repository navigation
fix(guards): raise ValueError for values too large for float conversion - #740
ompatil1906 wants to merge 1 commit into
Conversation
math.isfinite() raises OverflowError for ints/Fractions that cannot convert to float. Catch that and raise a field-named ValueError so callers of TransformConfig and plan_batches get a consistent error instead of an unlabelled OverflowError. Add regression coverage in field_guards, batching, and transform tests. Fixes Hebbian-Robotics#739
|
👋 Hi @ompatil1906 — thank you so much for your first contribution to HFlow! A maintainer will review your pull request as soon as possible. In the meantime:
💡 Tip: one open pull request per contributor at a time. Before starting an issue, check its sidebar for an assignee or a linked pull request. Either one means somebody is already on it; everything else is fair game. We are excited to have you here and appreciate your help making the project better! 🙌 |
[Medium impact] The PR changes error reporting across shared numeric validation paths. The PR appears safe to merge, with a non-blocking gap in error messages for extremely large values. Findings
|
| try: | ||
| finite = math.isfinite(number) | ||
| except OverflowError: | ||
| raise ValueError(f"{name} must be finite, got {number}") from None |
There was a problem hiding this comment.
Both new overflow handlers format the rejected number before raising the field-named error. On Python 3.11 with the default digit limit, 10**5000 and Fraction(10**5000, 1) make that formatting raise its own ValueError, which does not name the bad setting. This leaves the fix incomplete for larger inputs. Avoid formatting the full value in both handlers, and add tests beyond the digit limit.
|
Thanks for the contribution. #739 is already assigned to @yoveneim, so I’m keeping it reserved for them. You’re welcome to pick an unassigned good first issue. |
Summary
math.isfinite()raises an unlabelledOverflowErrorwhen given integers orFractions that cannot be converted to float (e.g.10**400). Public entry points such asTransformConfig(gop_seconds=...)andplan_batches(..., stagger_interval_s=...)therefore leakOverflowErrorinstead of the field-namedValueErrorused for every other invalid numeric input.Root cause
In
require_finite_floatandrequire_non_negative_real, the call tomath.isfiniteis not protected against overflow during the float conversion that CPython performs internally.Fix
Catch
OverflowErroraroundmath.isfiniteand re-raise aValueErrorthat names the field, matching the existing error style. No change to accepted value sets or to the behaviour of values that fit in a float.Verification
TransformConfig(gop_seconds=10**400)andplan_batches({'item': 1}, batch_count=1, stagger_interval_s=Fraction(10**400, 1))now raiseValueErrorcontaining the field name.tests/test_field_guards.pycover largeintfor the float guards and both largeint/Fractionfor the Real guard.tests/test_batching.pyandtests/test_transform.py.PYTHONPATH=src python -m pytest tests/test_field_guards.py -q→ 9 passed.Fixes #739
Need help on this PR? Tag
@codesmith-botwith what you need.