Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Jul 1, 2025

Describe your changes

If step is specified with a NumberColumn or ProgressColumn, we use it to influence value formatting on how many decimals it will show.

Testing Plan

  • Added unit tests.
  • Updated e2e tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Jul 1, 2025

πŸŽ‰ 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)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2025

βœ… PR preview is ready!

Name Link
πŸ“¦ Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11835/streamlit-1.46.1-py3-none-any.whl
πŸ•ΉοΈ Preview app pr-11835.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Jul 1, 2025
@lukasmasuch lukasmasuch changed the title Use max precision (step) to influence column config formatting Use step to influence column config number formatting Jul 1, 2025
@lukasmasuch lukasmasuch added the security-assessment-completed Security assessment has been completed for PR label Jul 1, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review July 1, 2025 18:40
@lukasmasuch lukasmasuch requested a review from Copilot July 1, 2025 18:48
Copy link
Contributor

Copilot AI left a 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 maxPrecision to all relevant Intl.NumberFormatOptions in formatNumber
  • Extend unit tests in utils.test.ts to validate precision for each format
  • Update the E2E DataFrame config to include step=0.1 for 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 formatIntlNumberWithLocales lists parameters format and maxPrecision, but the function signature takes (value, options). Update the doc to describe the options parameter 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 exercise maxPrecision behavior in E2E tests, consider adding step to other currency columns (e.g., euro, yen) or adding a ProgressColumn case.
        "dollar": st.column_config.NumberColumn(format="dollar", step=0.1),

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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.

@lukasmasuch lukasmasuch merged commit e9d613b into develop Jul 2, 2025
38 checks passed
@lukasmasuch lukasmasuch deleted the use-max-precision-for-formatting branch July 2, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants