UnicodeEncodeError with to_sql and unicode column names #11431

Closed
jorisvandenbossche opened this Issue Oct 26, 2015 · 1 comment

Comments

Projects
None yet
2 participants

From SO: http://stackoverflow.com/questions/33337798/unicodeencodeerror-when-using-pandas-method-to-sql-on-a-dataframe-with-unicode-c

To reproduce:

from sqlalchemy import create_engine 
engine = create_engine('sqlite:///:memory:')
df = pd.DataFrame([[1,2],[3,4]], columns = [u'\xe9',u'b'])
df.to_sql('data', engine, if_exists='replace', index=False)

which gives UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128), because of this line: https://github.com/pydata/pandas/blob/master/pandas/io/sql.py#L856, where it stringifies the individual columns names with str (which fails on python 2 with unicode).

jorisvandenbossche added this to the 0.17.1 milestone Oct 26, 2015

I suppose we should just use compat.text_type instead of str

@jreback jreback modified the milestone: Next Major Release, 0.17.1 Nov 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment