{{ message }}
FIX: make EngFormatter respect axes.formatter.use_locale rcParam - #32281
Open
christianaurichzm wants to merge 1 commit into
Open
FIX: make EngFormatter respect axes.formatter.use_locale rcParam#32281christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
EngFormatter subclasses ScalarFormatter, but the inherited locale machinery is reachable only in the offset path. The normal engineering formatting path both forces the flag off at construction, by passing useLocale=False to super().__init__, and bypasses locale-aware formatting, by interpolating the mantissa directly. The rcParam therefore had no effect, and set_useLocale flipped a flag that format_data never consulted. Pass useLocale through to ScalarFormatter and add the matching keyword argument, so that the rcParam applies and an explicit value overrides it. When locale formatting is on, the mantissa goes through locale.format_string, and the separators it introduces are escaped for mathtext the same way ScalarFormatter already escapes them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
EngFormatterignoresaxes.formatter.use_localewhen formatting the mantissa.With
de_DE.UTF-8:There are two causes:
EngFormatter.__init__passesuseLocale=FalsetoScalarFormatter, andformat_dataformats the mantissa directly instead of using locale-aware formatting. Because of the latter, evenset_useLocale(True)does not affect the normalformat_datapath. Locale-aware formatting is currently only used for the offset path.This change passes
useLocalethrough toScalarFormatter, adds it as anEngFormatterkeyword argument, and applies locale formatting to the mantissa. For MathText, locale separators are escaped to avoid punctuation spacing.Tests cover the rcParam, explicit
useLocalevalues, the inherited setter, and MathText.I consider this a bug fix:
EngFormatteralready inherits the locale API fromScalarFormatter, but does not honor it consistently. #13477 fixed the same kind of issue foraxes.unicode_minus.The new constructor keyword is the only public API addition here and can be split out if preferred.
Related: #25006 concerns the same rcParam, but a different issue involving locale initialization/reset behavior.
PR quality check