MONAI
MONAI copied to clipboard
CSVSaver and write_metrics_reports fail on Windows for non-ASCII file names
On Windows the default encoding is often cp1252, and CSVSaver and write_metrics_reports open their CSV files without an encoding. If a file name contains characters cp1252 can't encode (for example Chinese characters), saving fails:
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1
Tested on Windows 11, Python 3.13, current dev, with a file name like "患者_01.nii.gz". The affected calls are in monai/data/csv_saver.py (line 76) and monai/handlers/utils.py (lines 109, 132, 164).
This is the same kind of problem as #9277 (fixed for bundle and datalist files in #9282). I can open a PR adding encoding="utf-8" with tests once #9282 is merged.