From 7ac59d1a36948ad7a9dfd40410101455837778d8 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 10 Aug 2026 20:08:06 +0800 Subject: [PATCH] Fix: set column type priority (#18054) --- rag/app/table.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rag/app/table.py b/rag/app/table.py index 7c7cbd1431..114f62dd58 100644 --- a/rag/app/table.py +++ b/rag/app/table.py @@ -392,7 +392,7 @@ def column_data_type(arr): if int(s) > 2**63 - 1: float_flag = True break - elif re.match(r"[+-]?[0-9.]{,19}$", s.replace("%%", "")) and not s.replace("%%", "").startswith("0"): + elif re.match(r"[+-]?[0-9]+\.[0-9]*$", s.replace("%%", "")) and not s.replace("%%", "").startswith("0"): counts["float"] += 1 elif re.match(r"(true|yes|是|\*|✓|✔|☑|✅|√|false|no|否|⍻|×)$", s, flags=re.IGNORECASE): counts["bool"] += 1 @@ -403,7 +403,10 @@ def column_data_type(arr): if float_flag: ty = "float" else: - counts = sorted(counts.items(), key=lambda x: x[1] * -1) + # When counts tie, prefer types that lose less data: + # text (lossless) > datetime > float > int > bool + type_priority = {"text": 0, "datetime": 1, "float": 2, "int": 3, "bool": 4} + counts = sorted(counts.items(), key=lambda x: (x[1] * -1, type_priority[x[0]])) ty = counts[0][0] for i in range(len(arr)): if arr[i] is None: