Skip to content

Commit eeeae29

Browse files
author
y-p
committed
BUG: fix decode errors in util.testing get_locales under py3
1 parent 1e3490f commit eeeae29

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pandas/util/testing.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,23 @@ def get_locales(prefix=None, normalize=True,
201201
return None
202202

203203
try:
204-
raw_locales = str(raw_locales, encoding=pd.options.display.encoding)
204+
# raw_locales is "\n" seperated list of locales
205+
# it may contain non-decodable parts, so split
206+
# extract what we can and then rejoin.
207+
locales = raw_locales.split(b'\n')
208+
raw_locales = []
209+
for x in raw_locales:
210+
try:
211+
raw_locales.append(str(x, encoding=pd.options.display.encoding))
212+
except:
213+
pass
205214
except TypeError:
206215
pass
207216

208217
if prefix is None:
209-
return _valid_locales(raw_locales.splitlines(), normalize)
218+
return _valid_locales(raw_locales, normalize)
210219

211-
found = re.compile('%s.*' % prefix).findall(raw_locales)
220+
found = re.compile('%s.*' % prefix).findall('\n'.join(raw_locales))
212221
return _valid_locales(found, normalize)
213222

214223

0 commit comments

Comments
 (0)