From 7b18f69b5ddc82ec12aa638af8bef7085b851bf3 Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Thu, 26 Nov 2026 11:21:01 +0800 Subject: [PATCH] fix(python): accept FLOAT NaN/Inf in Field.get_float_value 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. --- python/tests/test_write_and_read.py | 60 +++++++++++++++++++++++++++++ python/tsfile/field.py | 3 ++ 2 files changed, 63 insertions(+) diff --git a/python/tests/test_write_and_read.py b/python/tests/test_write_and_read.py index d9a492b62..6e3a45c63 100644 --- a/python/tests/test_write_and_read.py +++ b/python/tests/test_write_and_read.py @@ -1109,3 +1109,63 @@ def test_tree_all_datatype_query_to_dataframe_variants(): if __name__ == "__main__": os.chdir(os.path.dirname(os.path.abspath(__file__))) pytest.main(["test_write_and_read.py::test_row_record_write_and_read", "-s", "-v"]) + + +def test_float_nan_inf_write_and_read(): + import struct + + file_path = "float_nan_inf_write_and_read.tsfile" + specials = [float("nan"), float("inf"), float("-inf")] + expected_bits = [0x7FC00000, 0x7F800000, 0xFF800000] + + def f32_bits(value): + return struct.unpack("