Skip to content

Fix locale-aware SI value parsing - #3571

Open
Kkkakania wants to merge 2 commits into
pyqtgraph:masterfrom
Kkkakania:fix/locale-decimal-parsing
Open

Fix locale-aware SI value parsing#3571
Kkkakania wants to merge 2 commits into
pyqtgraph:masterfrom
Kkkakania:fix/locale-decimal-parsing

Conversation

@Kkkakania

Copy link
Copy Markdown
Contributor

Summary

  • normalize comma-decimal values before converting parsed SI values to numeric types
  • prevent numeric, period, or comma characters from being accepted as the start of a unit suffix
  • add coverage for comma-decimal SI evaluation
  • add symmetric rejection coverage for mismatched decimal separators

Root cause

The comma-aware regex returned the localized numeric token unchanged, so float() could not convert it. Separately, both locale regexes allowed any non-whitespace suffix start, which let a mismatched decimal separator and the remaining digits be treated as a suffix. That silently truncated the numeric value and could discard the intended SI prefix.

Validation

  • pytest tests/test_functions.py tests/widgets/test_spinbox.py -q (228 passed, 2 skipped)
  • git diff --check

Fixes #3568.
Fixes #3569.

@Kkkakania
Kkkakania marked this pull request as ready for review August 9, 2026 09:55
@oyvindlr

Copy link
Copy Markdown
Contributor

Looks good. I originally introduced the locale-aware SI-value parsing, so I checked your PR. The siParse bug seems to have been an oversight, while the other bug was introduced in #3546 when "\w" was changed to "\S" to allow parsing of "°". This change allows that, and also fixes the bug introduced by that change.

@j9ac9k

j9ac9k commented Aug 13, 2026

Copy link
Copy Markdown
Member

This is one of those cases where we will want a test that has many many parametrized inputs, with regular expressions this complicated (especially without the use of re.VERBOSE) it's super easy to overlook something.

@Kkkakania

Copy link
Copy Markdown
Contributor Author

Thanks, I've expanded the coverage into a 26-case parameterized matrix. It now exercises period and comma locales across signed values, leading and trailing decimals, exponents, SI prefixes, Unicode units, and rejection of mixed or mismatched separators. The focused siParse/siEval run passes all 65 selected tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants