Skip to content

Commit a2dc5d1

Browse files
committed
BUG: reverting conv_unicode but keeping configurable encoding
1 parent 7c54141 commit a2dc5d1

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

pandas/core/format.py

+5-20
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ def to_string(self):
137137
_strlen = len
138138
else:
139139
def _encode_diff(x):
140-
return len(x) - len(x.decode('utf-8'))
140+
return len(x) - len(x.decode(print_config.encoding))
141141

142142
def _strlen(x):
143143
try:
144-
return len(x.decode('utf-8'))
144+
return len(x.decode(print_config.encoding))
145145
except UnicodeError:
146146
return len(x)
147147

@@ -489,30 +489,15 @@ def __init__(self, values, digits=7, formatter=None, na_rep='NaN',
489489
self.justify = justify
490490

491491
def get_result(self):
492-
if self._conv_unicode():
492+
if self._have_unicode():
493493
fmt_values = self._format_strings(use_unicode=True)
494494
else:
495495
fmt_values = self._format_strings(use_unicode=False)
496496

497497
return _make_fixed_width(fmt_values, self.justify)
498498

499-
def _conv_unicode(self):
500-
#check if any needs and can be converted to nonascii encoding
501-
def _nonascii(x):
502-
if isinstance(x, unicode):
503-
return True
504-
try:
505-
if isinstance(x, str):
506-
x.decode('ascii')
507-
return False
508-
except UnicodeError:
509-
try:
510-
x.decode(print_config.encoding)
511-
return True
512-
except UnicodeError:
513-
return False
514-
return False
515-
mask = lib.map_infer(self.values, _nonascii)
499+
def _have_unicode(self):
500+
mask = lib.map_infer(self.values, lambda x: isinstance(x, unicode))
516501
return mask.any()
517502

518503
def _format_strings(self, use_unicode=False):

0 commit comments

Comments
 (0)