Skip to content

Commit 8f7caa5

Browse files
committed
BUG: unicode repr handling fix for Python 3 re #1292, #1279
1 parent 0f4f99a commit 8f7caa5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pandas/core/format.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def to_string(self):
116116
result = ['%s %s'] * len(fmt_values)
117117
for i, (k, v) in enumerate(izip(fmt_index[1:], fmt_values)):
118118
try:
119-
idx = k.ljust(pad_space + (len(k) - len(k.decode('utf-8'))))
119+
idx = k.ljust(pad_space + _encode_diff(k))
120120
except UnicodeEncodeError:
121121
idx = k.ljust(pad_space)
122122
result[i] = result[i] % (idx, v)
@@ -130,6 +130,11 @@ def to_string(self):
130130

131131
return '\n'.join(result)
132132

133+
if py3compat.PY3: # pragma: no cover
134+
_encode_diff = lambda x: 0
135+
else:
136+
def _encode_diff(x):
137+
return len(x) - len(x.decode('utf-8'))
133138

134139
class DataFrameFormatter(object):
135140
"""

0 commit comments

Comments
 (0)