Skip to content

fix(python): accept FLOAT NaN/Inf in Field.get_float_value - #1153

Merged
ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:fix-168-float-nan-inf
Nov 27, 2026
Merged

ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:fix-168-float-nan-inf

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

Problem

Field.get_float_value in python/tsfile/field.py rejects FLOAT NaN/Inf
on write with OverflowError, because the float32 range check
(min_float32 <= value <= max_float32) evaluates to False for non-finite
values. This affects the tree-model write_row_record path for every
FLOAT-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_range and Field.get_double_value:

if not math.isfinite(self.value):
    return np.float32(self.value)

Test

Adds test_float_nan_inf_write_and_read, which writes FLOAT NaN/+Inf/-Inf
through the tree model with both ALP and PLAIN encodings and verifies
bit-level readback (0x7fc00000, 0x7f800000, 0xff800000).

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@ColinLeeo
ColinLeeo merged commit 0891c73 into apache:develop Nov 27, 2026
18 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.

2 participants