codeant-ai-for-open-source[bot] commented on code in PR #45817:
URL: https://github.com/apache/superset/pull/45817#discussion_r4411606601


##########
superset/charts/client_processing.py:
##########
@@ -1222,6 +1223,87 @@ def merge_currency_formats(
     return currency_formats
 
 
+def apply_export_number_formats(
+    df: pd.DataFrame,
+    coltypes: list[GenericDataType],
+    form_data: dict[str, Any],
+    datasource: Optional[Union["BaseDatasource", "Query"]] = None,
+) -> pd.DataFrame:
+    """Format numeric columns as display text for a chart-data export.
+
+    Each numeric column (by ``coltypes``, aligned with ``df.columns``) is
+    resolved to its configured d3 format, currency and small-number format the
+    same way the live Table plugin does -- ``column_config`` overrides first,
+    then the datasource's saved per-metric formats -- and handed to
+    ``format_column``. A numeric column with nothing configured takes the
+    fixed-point fallback so its cells are never serialized as raw floats.
+    Non-numeric columns, nulls, NaN and infinity are left to the existing
+    helpers and pass through unchanged. The passed frame is mutated in place 
and
+    returned; the helper runs no query and performs no I/O.
+    """
+    saved_formats, verbose_map = get_datasource_column_formats(datasource)
+    saved_currency_formats, _ = get_datasource_currency_formats(datasource)
+    column_config = form_data.get("column_config") or {}
+
+    def label_of(name: str) -> str:
+        """Return the column label as it appears in ``df`` 
(verbose-renamed)."""
+        return name if name in df.columns else verbose_map.get(name, name)
+
+    # Index the per-column overrides by the label present in ``df`` so the
+    # lookups line up with the (possibly verbose-renamed) frame columns.
+    number_format_by_label = {
+        label_of(name): fmt for name, fmt in saved_formats.items()
+    }
+    currency_by_label = {
+        label_of(name): currency for name, currency in 
saved_currency_formats.items()
+    }
+    config_by_label = {label_of(name): config for name, config in 
column_config.items()}
+
+    numeric_columns = {
+        column
+        for column, coltype in zip(df.columns, coltypes, strict=True)
+        if coltype == GenericDataType.NUMERIC
+    }
+
+    for column in df.columns:
+        if column not in numeric_columns:
+            continue
+
+        config = config_by_label.get(column) or {}
+        configured_currency = config.get("currencyFormat") or {}
+        # The small-number formatter is built from this object whether or not a
+        # symbol survived in it, so an absent one has to stay distinguishable
+        # from a cleared one.
+        small_currency = config.get("currencyFormat")
+        number_format = config.get("d3NumberFormat") or 
number_format_by_label.get(
+            column
+        )
+        currency = (
+            configured_currency
+            if configured_currency.get("symbol")
+            else currency_by_label.get(column) or {}
+        )
+        # A cleared Select leaves a blank string behind, which the browser
+        # treats as unset.
+        small_number_format = (config.get("d3SmallNumberFormat") or 
"").strip() or None
+
+        if number_format or currency.get("symbol") or small_number_format:

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `e4c3bce`.
   
   Percent metric columns are detected by their prefixed labels and passed to 
`format_column` with `PERCENT_3_POINT` as the default format.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



##########
superset/common/query_context_processor.py:
##########
@@ -644,6 +646,14 @@ def get_data(
             if verbose_map:
                 df.columns = [verbose_map.get(column, column) for column in 
columns]
 
+            if is_feature_enabled("EXPORT_FORMATTED_NUMBERS"):
+                apply_export_number_formats(
+                    df,
+                    coltypes,
+                    self._query_context.form_data or {},
+                    self._qc_datasource,
+                )

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `e4c3bce`.
   
   For formatted XLSX exports, numeric columns are passed to 
`excel.apply_column_types` as strings, preventing formatted values such as 
`3.50` from being coerced back to numbers.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



-- 
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]

Reply via email to