Extend sprintf to support thousand separator#13284
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
|
@cursor review |
There was a problem hiding this comment.
Pull request overview
This PR vendors the sprintf-js library (converting it to TypeScript) and extends it with thousand separator support using , and _ flags, mirroring Python's format mini-language (e.g., f"{x:,}" and f"{x:_}").
Key changes:
- Vendored sprintf-js as TypeScript with thousand separator support (
%,dfor comma,%_dfor underscore) - Removed npm dependency on sprintf-js package
- Updated all import statements to use vendored version
- Added comprehensive test coverage for new formatting features
Reviewed changes
Copilot reviewed 9 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| frontend/yarn.lock | Removed sprintf-js and @types/sprintf-js dependencies from lockfile |
| frontend/lib/src/vendor/sprintf.js/sprintfjs.ts | New vendored sprintf implementation with thousand separator support |
| frontend/lib/src/vendor/sprintf.js/sprintfjs.test.ts | Comprehensive tests for sprintf functionality including new thousand separator formats |
| frontend/lib/src/vendor/sprintf.js/sprintfjs-LICENSE.txt | BSD-3-Clause license file for vendored sprintf library |
| frontend/lib/src/vendor/fzy.js/fuzzySearch.ts | Removed Streamlit copyright header and reordered exports (cosmetic changes to vendored file) |
| frontend/lib/src/vendor/fzy.js/fuzzySearch.test.ts | Removed Streamlit copyright header (cosmetic change to vendored file) |
| frontend/lib/src/util/formatNumber.ts | Updated import to use vendored sprintf; added documentation for thousand separator flags |
| frontend/lib/src/util/formatNumber.test.ts | Added test cases for thousand separator formatting, removed now-valid test cases from invalid list |
| frontend/lib/src/components/widgets/Slider/Slider.tsx | Updated import to use vendored sprintf |
| frontend/lib/src/components/widgets/NumberInput/utils.ts | Updated import to use vendored sprintf |
| frontend/lib/src/components/widgets/DataFrame/columns/ProgressColumn.test.ts | Added test cases for thousand separator formatting, removed now-valid test cases from invalid list |
| frontend/lib/src/components/widgets/DataFrame/columns/NumberColumn.test.ts | Added test cases for thousand separator formatting, removed now-valid test cases from invalid list |
| frontend/lib/package.json | Removed sprintf-js and @types/sprintf-js from dependencies |
| NOTICES | Updated license attribution for sprintf library (issue: duplicate entry remains) |
| Makefile | Added sprintfjs-LICENSE.txt to license append script |
📉 Frontend coverage change detectedThe frontend unit test (vitest) coverage has decreased by 0.0000%
✅ Coverage change is within normal range. |
…h-thousend-sep-support
SummaryThis PR vendors the sprintf-js library (converting it to TypeScript) and extends it to support thousand separator formatting via Key changes:
Code QualityThe implementation is well-structured and follows good practices: Positives:
Minor observations:
Test CoverageTest coverage is excellent: sprintf unit tests (
Updated integration tests:
Test patterns follow best practices:
Backwards CompatibilityFully backwards compatible:
API compatibility:
Security & RiskNo security concerns identified:
Low regression risk:
RecommendationsNo blocking issues found. A few optional suggestions:
VerdictAPPROVED: This PR is well-implemented with excellent test coverage, maintains backwards compatibility, and properly handles the vendored library's licensing. The thousand separator feature is a valuable addition that aligns with Python's format specification, making number formatting more intuitive for Streamlit users. This is an automated AI review. Please verify the feedback and use your judgment. |
There was a problem hiding this comment.
"source.organizeImports": "explicit" interferes with the eslint import sorting.
| "typescript.enablePromptUseWorkspaceTsdk": true, | ||
| "git.branchProtection": ["develop"] | ||
| "git.branchProtection": ["develop"], | ||
| "prettier.configPath": "frontend/.prettierrc" |
There was a problem hiding this comment.
nit: In the future, please put these kinds of changes in a separate PR to keep the diffs focused.
| @@ -1,3 +1,2 @@ | |||
| vendor | |||
There was a problem hiding this comment.
nit: Same comment as above, these changes would be helpful as a separate PR to keep the noise down.
Rendered spec: https://issues.streamlit.app/spec_renderer?pr=13293 ## GitHub Issue Link (if applicable) - Related feature requests: - #1301 - #7702 - Prototype: - #13284 ## Open Questions --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Describe your changes
Vendors in the sprintf-js library (only a single file) and modifies it slightly to support setting the thousand separator in the python printf format:
GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.