```
feat(excel_storage_service): 改进Excel数据类型检测逻辑 移除了空值进行类型检查,避免空数据导致的错误判断。对于整数类型, 增加了范围检查以确保数值在INT范围内;对于浮点数类型,增加了 范围验证以确保数值在有效范围内。超出范围的数值将被标记为TEXT类型, 提高数据类型的准确性。 ```
This commit is contained in:
@@ -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):
|
||||
# 检查是否所有值都能放入 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):
|
||||
# 检查是否所有值都能放入 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):
|
||||
|
||||
Reference in New Issue
Block a user