8000 Tick formatter does not support grouping with locale by z0rgy · Pull Request #8987 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test and API note for locale grouping in ScalarFormatter.
  • Loading branch information
QuLogic committed Sep 23, 2020
commit c3a18b38153fe8ba1b9e0232c4fc09cbc3779ba4
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/behavior/8987-Z.rst
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`.
18 changes: 17 additions & 1 deletion lib/matplotlib/tests/test_ticker.py
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
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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):
Expand Down
0