8000 Merge pull request #8987 from z0rgy/patch-2 · matplotlib/matplotlib@2e61658 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e61658

Browse files
authored
Merge pull request #8987 from z0rgy/patch-2
Tick formatter does not support grouping with locale
2 parents 3e88c9f + a1af478 commit 2e61658

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ omit = matplotlib/_version.py
77

88
[report]
99
exclude_lines =
10+
pragma: no cover
1011
raise NotImplemented
1112
def __str__
1213
def __repr__
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') # pragma: no cover
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):

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def _format_maybe_minus_and_locale(self, fmt, arg):
612612
"""
613613
Format *arg* with *fmt*, applying unicode minus and locale if desired.
614614
"""
615-
return self.fix_minus(locale.format_string(fmt, (arg,))
615+
return self.fix_minus(locale.format_string(fmt, (arg,), True)
616616
if self._useLocale else fmt % arg)
617617

618618
def get_useMathText(self):

0 commit comments

Comments
 (0)
0