Skip to content

Commit

Permalink
Merge pull request #227 from CartoDB/column-encodings-fix
Browse files Browse the repository at this point in the history
encodes to utf-8 to avoid issues between py2/3
  • Loading branch information
andy-esch authored Oct 10, 2017
2 parents 3ccbd40 + 82a1d31 commit a694cfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cartoframes/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ def remove_tempfile(filepath):
self._debug_print(tempfile=tempfile)
df.drop(geom_col, axis=1, errors='ignore').to_csv(path_or_buf=tempfile,
na_rep='',
header=pgcolnames)
header=pgcolnames,
encoding='utf-8')

with open(tempfile, 'rb') as f:
res = self._auth_send('api/v1/imports', 'POST',
Expand Down
14 changes: 14 additions & 0 deletions test/test_context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

"""Unit tests for cartoframes.layers"""
import unittest
import os
Expand Down Expand Up @@ -260,6 +262,18 @@ def test_cartocontext_write(self):
# util columns + new column of type number
self.assertDictEqual(cols['fields'], expected_schema)

# test properly encoding
df = pd.DataFrame({'vals':[1,2],'strings':['a','ô']})
cc.write(df, self.test_write_table, overwrite=True)

# check if table exists
resp = self.sql_client.send('''
SELECT *
FROM {table}
LIMIT 0
'''.format(table=self.test_write_table))
self.assertIsNotNone(resp)

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping')
def test_cartocontext_mixed_case(self):
cc = cartoframes.CartoContext(base_url=self.baseurl,
Expand Down

0 comments on commit a694cfa

Please sign in to comment.