Add string sanitization for Excel export#408
Conversation
Signed-off-by: ImMin5 <mino@megazone.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds string sanitization for Excel exports by removing illegal characters from strings before writing the DataFrame to Excel. Key changes include:
- Adding a helper static method (_sanitize_string) to clean string values.
- Integrating the sanitization step into the Excel export process.
- Adjusting import order to support the new functionality.
| df = df.map(ExportManager._sanitize_string) | ||
| df.to_excel(writer, sheet_name=sheet_name, index=False, startrow=start_row) |
There was a problem hiding this comment.
The use of df.map is intended to apply the sanitation function to every cell in the DataFrame, but DataFrame.map operates on columns (or fails entirely) while DataFrame.applymap should be used for elementwise operations. Consider replacing it with df = df.applymap(ExportManager._sanitize_string).
| df = df.map(ExportManager._sanitize_string) | |
| df.to_excel(writer, sheet_name=sheet_name, index=False, startrow=start_row) | |
| df = df.applymap(ExportManager._sanitize_string) |
There was a problem hiding this comment.
FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.
In Pandas versions prior to 2.1.0, DataFrame.applymap() was the correct method to apply an elementwise operation across a DataFrame.
However, since Pandas 2.1.0, applymap() has been deprecated and the recommended approach is to use DataFrame.map() for elementwise operations.
Therefore, if targeting Pandas 2.1.0 or newer, it is correct to replace applymap() with map().
Category
Description
Known issue