-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Tick formatter does not support grouping with locale #8987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
``ScalarFormatter`` *useLocale* option obeys grouping | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
When the `~.ScalarFormatter` option *useLocale* is enabled (or | ||
:rc:`axes.formatter.use_locale` is *True*) and the configured locale uses | ||
grouping, a separator will be added as described in `locale.format_string`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from contextlib import nullcontext | ||
import re | ||
import itertools | ||
import locale | ||
import re | ||
|
||
import numpy as np | ||
from numpy.testing import assert_almost_equal, assert_array_equal | ||
|
@@ -546,6 +547,21 @@ def test_use_offset(self, use_offset): | |
tmp_form = mticker.ScalarFormatter() | ||
assert use_offset == tmp_form.get_useOffset() | ||
|
||
def test_use_locale(self): | ||
conv = locale.localeconv() | ||
sep = conv['thousands_sep'] | ||
if not sep or conv['grouping'][-1:] in ([], [locale.CHAR_MAX]): | ||
pytest.skip('Locale does not apply grouping') # pragma: no cover | ||
|
||
with mpl.rc_context({'axes.formatter.use_locale': True}): | ||
tmp_form = mticker.ScalarFormatter() | ||
assert tmp_form.get_useLocale() | ||
|
||
tmp_form.create_dummy_axis() | ||
tmp_form.set_bounds(0, 10) | ||
tmp_form.set_locs([1, 2, 3]) | ||
assert sep in tmp_form(1e9) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the easiest test to follow, and seems to use a default locale? If the locale doesn't have the separator does this test anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it accesses the POSIX locale database, I wasn't sure if you would need to have the locale installed to have it work, so didn't want to hardcode anything specific. But note that the test framework does set the locale to en_US, so it's not an environment-specific default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I you feel it tests something real then I'm fine with it, but it just seems a little self-referential. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, a little self-referential, but it would catch if say, in the recent refactor that caused the conflicts, the locale setting was lost somewhere. |
||
|
||
@pytest.mark.parametrize( | ||
'sci_type, scilimits, lim, orderOfMag, fewticks', scilimits_data) | ||
def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks): | ||
|
Uh oh!
There was an error while loading. Please reload this page.