From a5e6e5895e24c9f55945da2ba2cbd25dcdf9b828 Mon Sep 17 00:00:00 2001 From: "xingjun.wang" Date: Sat, 17 Feb 2024 16:45:01 +0800 Subject: [PATCH] add escapechar for dataframe to_csv func --- modelscope/hub/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modelscope/hub/api.py b/modelscope/hub/api.py index ac66e11c..6b9748f5 100644 --- a/modelscope/hub/api.py +++ b/modelscope/hub/api.py @@ -774,7 +774,11 @@ class HubApi: else: with_header = False chunk_df = pd.DataFrame(chunk) - chunk_df.to_csv(f, index=False, header=with_header) + try: + chunk_df.to_csv(f, index=False, header=with_header) + except Exception as e: + logger.info(f'Failed to dump dataframe chunk to csv: {e}, try to set escapechar') + chunk_df.to_csv(f, index=False, header=with_header, escapechar='\\') iter_num += 1 else: # csv or others