From 1a54d40e01081069c3f77f328e557d71a06e01a1 Mon Sep 17 00:00:00 2001 From: KiriAky 107 Date: Thu, 2 Apr 2026 10:44:13 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(excel=5Fstorage=5Fservice):=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9BExcel=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了空值进行类型检查,避免空数据导致的错误判断。对于整数类型, 增加了范围检查以确保数值在INT范围内;对于浮点数类型,增加了 范围验证以确保数值在有效范围内。超出范围的数值将被标记为TEXT类型, 提高数据类型的准确性。 ``` --- backend/app/services/excel_storage_service.py | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/app/services/excel_storage_service.py b/backend/app/services/excel_storage_service.py index 0c7130d..62a54c6 100644 --- a/backend/app/services/excel_storage_service.py +++ b/backend/app/services/excel_storage_service.py @@ -113,12 +113,35 @@ class ExcelStorageService: Returns: 类型名称 """ + # 移除空值进行类型检查 + non_null = series.dropna() + if len(non_null) == 0: + return "TEXT" + dtype = series.dtype + # 整数类型检查 if pd.api.types.is_integer_dtype(dtype): - return "INTEGER" + # 检查是否所有值都能放入 INT 范围 + try: + int_values = non_null.astype('int64') + if int_values.min() >= -2147483648 and int_values.max() <= 2147483647: + return "INTEGER" + else: + # 超出 INT 范围,使用 TEXT + return "TEXT" + except (ValueError, OverflowError): + return "TEXT" elif pd.api.types.is_float_dtype(dtype): - return "FLOAT" + # 检查是否所有值都能放入 FLOAT + try: + float_values = non_null.astype('float64') + if float_values.min() >= -1e308 and float_values.max() <= 1e308: + return "FLOAT" + else: + return "TEXT" + except (ValueError, OverflowError): + return "TEXT" elif pd.api.types.is_datetime64_any_dtype(dtype): return "DATETIME" elif pd.api.types.is_bool_dtype(dtype):