Repository navigation
fix(expressions): reject non-finite floats on conversion to Decimal - #4287
Open
AP24110011695 wants to merge 1 commit into
Open
AP24110011695 wants to merge 1 commit into
AP24110011695 wants to merge 1 commit into
Conversation
float('inf') is a valid float/double literal, but converting it to a
Decimal type crashed with a bare decimal.InvalidOperation instead of the
ValueError every other impossible conversion in this module raises.
NaN is already rejected at literal construction; infinity now gets a
clean, consistent domain error.
Signed-off-by: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4286
Problem
float('inf')is a valid float/double literal (only NaN is rejected at construction), but converting it to aDecimalTypeleaked a baredecimal.InvalidOperationfrom insideDecimal.quantize()— with no context and inconsistent with every other impossible conversion in the module, which raisesValueError("Could not convert X into a Y…"):Fix
Both
FloatLiteral.to(DecimalType)andDoubleLiteral.to(DecimalType)now raiseValueError("Could not convert inf into a decimal(9, 2), value is not finite")before quantizing. The message follows the suffix style introduced for this module in #4029.Tests
Two regression tests (fail on
mainwithdecimal.InvalidOperation, pass with this change):test_float_to_decimal_conversion_with_infinitytest_double_to_decimal_conversion_with_infinityFull
tests/expressions/test_literals.py: 177 passed.tests/test_transforms.py: 275 passed with the same 17 pyarrow-parametrized failures as unmodifiedmainin this environment (baseline verified).ruff(pinned 0.14.3) check + format clean on both touched files.Transparent disclosure: developed and verified with AI assistance under human direction, per the repo's agent guidelines.