Skip to content

Commit 25059ee

Browse files
timcerajreback
authored andcommitted
BUG: Need 'windows-1252' encoding for locale names. (#27368)
1 parent 56b2fd8 commit 25059ee

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Datetimelike
241241
- Bug in :class:`Week` with ``weekday`` incorrectly raising ``AttributeError`` instead of ``TypeError`` when adding or subtracting an invalid type (:issue:`28530`)
242242
- Bug in :class:`DataFrame` arithmetic operations when operating with a :class:`Series` with dtype `'timedelta64[ns]'` (:issue:`28049`)
243243
- Bug in :func:`pandas.core.groupby.generic.SeriesGroupBy.apply` raising ``ValueError`` when a column in the original DataFrame is a datetime and the column labels are not standard integers (:issue:`28247`)
244+
- Bug in :func:`pandas._config.localization.get_locales` where the ``locales -a`` encodes the locales list as windows-1252 (:issue:`23638`, :issue:`24760`, :issue:`27368`)
244245

245246
Timedelta
246247
^^^^^^^^^

pandas/_config/localization.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@ def get_locales(prefix=None, normalize=True, locale_getter=_default_locale_gette
145145
raw_locales = raw_locales.split(b"\n")
146146
out_locales = []
147147
for x in raw_locales:
148-
out_locales.append(str(x, encoding=options.display.encoding))
148+
try:
149+
out_locales.append(str(x, encoding=options.display.encoding))
150+
except UnicodeError:
151+
# 'locale -a' is used to populated 'raw_locales' and on
152+
# Redhat 7 Linux (and maybe others) prints locale names
153+
# using windows-1252 encoding. Bug only triggered by
154+
# a few special characters and when there is an
155+
# extensive list of installed locales.
156+
out_locales.append(str(x, encoding="windows-1252"))
149157

150158
except TypeError:
151159
pass

0 commit comments

Comments
 (0)