Fix: set column type priority (#18054)

This commit is contained in:
Lynn
2026-08-10 20:08:06 +08:00
committed by GitHub
parent b978f94fa6
commit 7ac59d1a36

View File

@@ -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: