-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
Description
I am using anaconda python 2.7, pandas 0.12.0, with from __future__ import unicode_literals
The bug
When I call dataframe.to_csv(fname, sep=sep, index=index, float_format=float_format, **csvkwargs) and pass in sep=',', pandas throws an exception:
File "C:\Anaconda\lib\site-packages\pandas\core\frame.py", line 1410, in to_csv formatter.save() File "C:\Anaconda\lib\site-packages\pandas\core\format.py", line 959, in save quoting=self.quoting) File "C:\Anaconda\lib\site-packages\pandas\core\common.py", line 1770, in __init__ self.writer = csv.writer(self.queue, dialect=dialect, **kwds) TypeError: "delimiter" must be an 1-character string The workaround
If I change this to:
dataframe.to_csv(fname, sep=str(sep), index=index, float_format=float_format, **csvkwargs) everything works as you might expect. (I have observerved this error both when I pass in no encoding and when I pass in encoding='Windows 1252')
What I would expect
When passed unicode, pandas should:
- If encoding is set, and the unicode
sepis one character long i.e.len(sep)==1(is it really necessary to have this one character restriction?), use thesepcharacter passed in (encoded appropriately) - If encoding is not set, then check that the default encoding (I don't know whether this is ascii or platform dependent) of
sepis only one character long