Skip to content

Commit 6606bc0

Browse files
committed
fix: resolve ambiguous boolean value error in pandas Series operations
1 parent 1780750 commit 6606bc0

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

backend/common/utils/data_format.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ class DataFormat:
88
def safe_convert_to_string(df):
99
df_copy = df.copy()
1010

11-
def format_value(x):
12-
if pd.isna(x):
13-
return ""
14-
15-
return "\u200b" + str(x)
16-
1711
for col in df_copy.columns:
18-
df_copy[col] = df_copy[col].apply(format_value)
12+
# 使用map避免ambiguous truth value问题
13+
df_copy[col] = df_copy[col].map(
14+
# 关键:在数字字符串前添加零宽空格,阻止pandas的自动格式化
15+
lambda x: "" if pd.isna(x) else "\u200b" + str(x)
16+
)
1917

2018
return df_copy
2119

0 commit comments

Comments
 (0)