Skip to content

Commit 10774ee

Browse files
committed
TST: Propagate lc_var in can_set_locale
Backported from pandas-devgh-21739.
1 parent 59c1640 commit 10774ee

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pandas/tests/util/test_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def test_set_locale(self):
466466
enc = codecs.lookup(enc).name
467467
new_locale = lang, enc
468468

469-
if not tm._can_set_locale(new_locale):
469+
if not tm.can_set_locale(new_locale):
470470
with pytest.raises(locale.Error):
471471
with tm.set_locale(new_locale):
472472
pass

pandas/util/testing.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,17 @@ def get_locales(prefix=None, normalize=True,
470470

471471
@contextmanager
472472
def set_locale(new_locale, lc_var=locale.LC_ALL):
473-
"""Context manager for temporarily setting a locale.
473+
"""
474+
Context manager for temporarily setting a locale.
474475
475476
Parameters
476477
----------
477478
new_locale : str or tuple
478479
A string of the form <language_country>.<encoding>. For example to set
479480
the current locale to US English with a UTF8 encoding, you would pass
480481
"en_US.UTF-8".
482+
lc_var : int, default `locale.LC_ALL`
483+
The category of the locale being set.
481484
482485
Notes
483486
-----
@@ -503,21 +506,23 @@ def set_locale(new_locale, lc_var=locale.LC_ALL):
503506
locale.setlocale(lc_var, current_locale)
504507

505508

506-
def _can_set_locale(lc):
507-
"""Check to see if we can set a locale without throwing an exception.
509+
def can_set_locale(lc, lc_var=locale.LC_ALL):
510+
"""Check to see if we can set a locale without throwing an Exception.
508511
509512
Parameters
510513
----------
511514
lc : str
512515
The locale to attempt to set.
516+
lc_var : int, default `locale.LC_ALL`
517+
The category of the locale being set.
513518
514519
Returns
515520
-------
516-
isvalid : bool
521+
is_valid : bool
517522
Whether the passed locale can be set
518523
"""
519524
try:
520-
with set_locale(lc):
525+
with set_locale(lc, lc_var=lc_var):
521526
pass
522527
except locale.Error: # horrible name for a Exception subclass
523528
return False
@@ -546,7 +551,7 @@ def _valid_locales(locales, normalize):
546551
else:
547552
normalizer = lambda x: x.strip()
548553

549-
return list(filter(_can_set_locale, map(normalizer, locales)))
554+
return list(filter(can_set_locale, map(normalizer, locales)))
550555

551556
# -----------------------------------------------------------------------------
552557
# Stdout / stderr decorators

0 commit comments

Comments
 (0)