Skip to content

Commit bc6e820

Browse files
committed
BUG: #680 clean up with check for py3compat
1 parent f925264 commit bc6e820

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

pandas/core/format.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from StringIO import StringIO
44
from pandas.core.common import adjoin, isnull, _format
55
from pandas.core.index import MultiIndex, _ensure_index
6+
from pandas.util import py3compat
67

78
import pandas.core.common as com
89
import numpy as np
@@ -209,17 +210,18 @@ def to_string(self, force_unicode=False):
209210
else:
210211
to_write.append(adjoin(1, *stringified))
211212

212-
if force_unicode:
213-
to_write = [unicode(s) for s in to_write]
214-
else:
215-
# generally everything is plain strings, which has ascii encoding.
216-
# problem is when there is a char with value over 127 - everything
217-
# then gets converted to unicode.
218-
try:
219-
for s in to_write:
220-
str(s)
221-
except UnicodeError:
213+
if not py3compat.PY3:
214+
if force_unicode:
222215
to_write = [unicode(s) for s in to_write]
216+
else:
217+
# generally everything is plain strings, which has ascii encoding.
218+
# problem is when there is a char with value over 127 - everything
219+
# then gets converted to unicode.
220+
try:
221+
for s in to_write:
222+
str(s)
223+
except UnicodeError:
224+
to_write = [unicode(s) for s in to_write]
223225

224226
self.buf.writelines(to_write)
225227

0 commit comments

Comments
 (0)