-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasIO CSVread_csv, to_csvread_csv, to_csvUnicodeUnicode stringsUnicode strings
Milestone
Description
# is missing the UTF8 BOM (encoded with default encoding UTF8)
with open('path_to_f', 'w') as f:
df.to_csv(f, encoding='utf-8-sig')
# is not missing the UTF8 BOM (encoded with passed encoding utf-8-sig)
df.to_csv('path_to_f', encoding='utf-8-sig')
I expect:
with open('path_to_f', 'w') as f:
df.to_csv(f, encoding='utf-8-sig')
To crash with TypeError: write() argument must be str, not bytes
and I expect:
with open('path_to_f', 'wb') as f:
df.to_csv(f, encoding='utf-8-sig')
To write the file correctly.
Copy pasta
#!/usr/bin/env python3
import pandas as pd
df = pd.DataFrame()
with open('file_one', 'w') as f:
df.to_csv(f, encoding='utf-8-sig')
assert open('file_one', 'rb').read() == b'""\n'
# is not missing the UTF8 BOM (encoded with passed encoding utf-8-sig)
df.to_csv('file_two', encoding='utf-8-sig')
assert open('file_two', 'rb').read() == b'\xef\xbb\xbf""\n'
Metadata
Metadata
Assignees
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasIO CSVread_csv, to_csvread_csv, to_csvUnicodeUnicode stringsUnicode strings