diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index ea52736cb11a7..cc33d1120b51e 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -239,6 +239,7 @@ Datetimelike - Bug in :class:`Week` with ``weekday`` incorrectly raising ``AttributeError`` instead of ``TypeError`` when adding or subtracting an invalid type (:issue:`28530`) - Bug in :class:`DataFrame` arithmetic operations when operating with a :class:`Series` with dtype `'timedelta64[ns]'` (:issue:`28049`) - 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`) +- 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`) Timedelta ^^^^^^^^^ diff --git a/pandas/_config/localization.py b/pandas/_config/localization.py index 9f750d8447c6a..ba60b1e003004 100644 --- a/pandas/_config/localization.py +++ b/pandas/_config/localization.py @@ -145,7 +145,15 @@ def get_locales(prefix=None, normalize=True, locale_getter=_default_locale_gette raw_locales = raw_locales.split(b"\n") out_locales = [] for x in raw_locales: - out_locales.append(str(x, encoding=options.display.encoding)) + try: + out_locales.append(str(x, encoding=options.display.encoding)) + except UnicodeError: + # 'locale -a' is used to populated 'raw_locales' and on + # Redhat 7 Linux (and maybe others) prints locale names + # using windows-1252 encoding. Bug only triggered by + # a few special characters and when there is an + # extensive list of installed locales. + out_locales.append(str(x, encoding="windows-1252")) except TypeError: pass