Repository navigation
fix(python): accept FLOAT NaN/Inf in Field.get_float_value - #1153
Merged
Merged
Conversation
Field.get_float_value rejected NaN/Inf with OverflowError because the float32 range check evaluates to False for non-finite values. Allow non-finite values through before the range check, matching Tablet._check_numeric_range and Field.get_double_value. Add a unit test that writes FLOAT NaN/Inf through the tree model with ALP and PLAIN encodings and verifies bit-level readback.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the FLOAT special-value handling and associated regression-test changes.
No open issues 🎉
What changed in this PR
This PR fixes Python tree-model row writes rejecting FLOAT NaN and infinity values, aligning Field.get_float_value with the existing Tablet and DOUBLE behavior.
Changes:
- Allow non-finite values through FLOAT conversion while retaining range checks for finite values.
- Add a regression test verifying bit-level readback of NaN, positive infinity, and negative infinity with ALP and PLAIN encodings.
| File | Description |
|---|---|
python/tsfile/field.py |
Accept non-finite values before checking the float32 range. |
python/tests/test_write_and_read.py |
Test FLOAT special-value round trips through tree-model row writes. |
Review effort: Balanced
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.
Problem
Field.get_float_valueinpython/tsfile/field.pyrejects FLOAT NaN/Infon write with
OverflowError, because the float32 range check(
min_float32 <= value <= max_float32) evaluates toFalsefor non-finitevalues. This affects the tree-model
write_row_recordpath for everyFLOAT-capable encoding; the DOUBLE path and the Tablet path are unaffected.
Fix
Allow non-finite values through before the range check, matching
Tablet._check_numeric_rangeandField.get_double_value:Test
Adds
test_float_nan_inf_write_and_read, which writes FLOAT NaN/+Inf/-Infthrough the tree model with both ALP and PLAIN encodings and verifies
bit-level readback (
0x7fc00000,0x7f800000,0xff800000).