sadpandajoe commented on code in PR #45439:
URL: https://github.com/apache/superset/pull/45439#discussion_r4321912375
##########
tests/unit_tests/charts/test_client_processing.py:
##########
@@ -2501,6 +2501,293 @@ def test_table_applies_si_number_format() -> None:
assert formatted["amount"].tolist() == ["1.23k"]
+def test_table_applies_small_number_format() -> None:
+ """
+ A cell below one in absolute value takes the column's small-number format.
+
+ ``formatColumnValue`` in the Table plugin picks the formatter per value, so
+ the report has to switch per cell rather than per column.
+ """
+ df = pd.DataFrame.from_dict({"ratio": {0: 0.0523, 1: 12.5, 2: -0.5, 3:
0.0}})
+ form_data = {
+ "viz_type": "table",
+ "metrics": ["ratio"],
+ "column_config": {
+ "ratio": {"d3NumberFormat": ",.2f", "d3SmallNumberFormat": ".1%"}
+ },
+ }
+ formatted = table(df, form_data)
+ assert formatted["ratio"].tolist() == ["5.2%", "12.50", "-50.0%", "0.0%"]
+
Review Comment:
None of the small-number tests put a value at or beyond the switch point, so
`is_small_number` could drift without a failure: changing `< 1` to `<= 1`, or
dropping the `abs()` so `-12.5` counts as small, still passes every case here
(the only negative is `-0.5`, which is small either way). Either slip would
render a large negative or exactly-1 cell as a percentage in a report. Could
this test also cover `1`, `-1` and `-12.5` with `,.2f` / `.1%`, expecting
`["1.00", "-1.00", "-12.50"]`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]