8000 Add test and API note for locale grouping in ScalarFormatter. · matplotlib/matplotlib@8d033e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d033e2

Browse files
committed
Add test and API note for locale grouping in ScalarFormatter.
1 parent 6d3de0c commit 8d033e2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
``ScalarFormatter`` *useLocale* option obeys grouping
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
When the `~.ScalarFormatter` option *useLocale* is enabled (or
5+
:rc:`axes.formatter.use_locale` is *True*) and the configured locale uses
6+
grouping, a separator will be added as described in `locale.format_string`.

lib/matplotlib/tests/test_ticker.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from contextlib import nullcontext
2-
import re
32
import itertools
3+
import locale
4+
import re
45

56
import numpy as np
67
from numpy.testing import assert_almost_equal, assert_array_equal
@@ -546,6 +547,21 @@ def test_use_offset(self, use_offset):
546547
tmp_form = mticker.ScalarFormatter()
547548
assert use_offset == tmp_form.get_useOffset()
548549

550+
def test_use_locale(self):
551+
conv = locale.localeconv()
552+
sep = conv['thousands_sep']
553+
if not sep or conv['grouping'][-1:] in ([], [locale.CHAR_MAX]):
554+
pytest.skip('Locale does not apply grouping')
555+
556+
with mpl.rc_context({'axes.formatter.use_locale': True}):
557+
tmp_form = mticker.ScalarFormatter()
558+
assert tmp_form.get_useLocale()
559+
560+
tmp_form.create_dummy_axis()
561+
tmp_form.set_bounds(0, 10)
562+
tmp_form.set_locs([1, 2, 3])
563+
assert sep in tmp_form(1e9)
564+
549565
@pytest.mark.parametrize(
550566
'sci_type, scilimits, lim, orderOfMag, fewticks', scilimits_data)
551567
def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks):

0 commit comments

Comments
 (0)
0