mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-12 11:43:39 +08:00
Fix: set column type priority (#18054)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user