-
Notifications
You must be signed in to change notification settings - Fork 4k
Use step to influence column config number formatting
#11835
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
Conversation
π Snyk checks have passed. No issues have been found so far.β security/snyk check is complete. No issues have been found. (View Details) β license/snyk check is complete. No issues have been found. (View Details) |
β PR preview is ready!
|
step to influence column config number formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
The PR enhances number formatting by using the step (exposed as maxPrecision) parameter in NumberColumn and ProgressColumn configs to control decimal precision, updates unit tests to cover this behavior across formats, and amends an E2E test to set a step on the dollar column.
- Apply
maxPrecisionto all relevantIntl.NumberFormatOptionsinformatNumber - Extend unit tests in
utils.test.tsto validate precision for each format - Update the E2E DataFrame config to include
step=0.1for the dollar column
Reviewed Changes
Copilot reviewed 3 out of 9 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| frontend/lib/src/components/widgets/DataFrame/columns/utils.ts | Apply maxPrecision in all formatNumber branches |
| frontend/lib/src/components/widgets/DataFrame/columns/utils.test.ts | Add it.each tests for maxPrecision across different formats |
| e2e_playwright/st_dataframe_config.py | Set step=0.1 on the dollar column config for E2E coverage |
Comments suppressed due to low confidence (2)
frontend/lib/src/components/widgets/DataFrame/columns/utils.ts:544
- The JSDoc for
formatIntlNumberWithLocaleslists parametersformatandmaxPrecision, but the function signature takes(value, options). Update the doc to describe theoptionsparameter instead.
* @param format - The format to use. If not provided, the default format is used.
e2e_playwright/st_dataframe_config.py:661
- [nitpick] Only the dollar column is configured with
step=0.1. To fully exercisemaxPrecisionbehavior in E2E tests, consider addingstepto other currency columns (e.g., euro, yen) or adding a ProgressColumn case.
"dollar": st.column_config.NumberColumn(format="dollar", step=0.1),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So Number column doesn't have format dollar, right? I think with format dollar and other currencies we should default to two decimal places if precision is not given by the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dollar is defaulting to two decimal places without a step provided. But in this specific case, it actually has a step=0.001 configured, which causes it to show three decimals.
| have unrestricted precision. In this case, some floats may display like | ||
| integers. Setting ``step`` for float columns will ensure a consistent | ||
| number of digits after the decimal even without setting ``format``. | ||
| number of digits after the decimal are displayed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's out of scope of this PR, but I find it confusing that this is called step but it is about precision. Is it also used for some kind of stepping, like adding quantities with a + button?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, its also used for step size when editing. But mainly visible with the date/time/datetime columns, not as visible with the number column yet. For these columns, setting step has impact on the editing and the formatting. The main reason why we called it step was also to be consistent on how the equivalent parameter is called in some of the widgets (e.g. number_input, time_input...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if we were designing this from scratch I would advocate for having two params, but not to change it now.
Describe your changes
If
stepis specified with a NumberColumn or ProgressColumn, we use it to influence value formatting on how many decimals it will show.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.