fitzee commented on code in PR #45527:
URL: https://github.com/apache/superset/pull/45527#discussion_r4330805472
##########
superset/charts/client_processing.py:
##########
@@ -1417,18 +1417,27 @@ def _is_default_index_column(series: pd.Series) -> bool:
def _read_excel_for_client_processing(
data: bytes,
form_data: dict[str, Any],
+ verbose_map: Optional[dict[str, str]] = None,
) -> pd.DataFrame:
df = pd.read_excel(BytesIO(data))
if len(df.columns) == 0:
return df
first_column = df.columns[0]
- expected_columns = {
+ expected_columns: set[str] = {
*get_column_names(form_data.get("columns")),
+ *get_column_names(form_data.get("all_columns")),
+ *get_column_names(form_data.get("groupby")),
*get_column_names(form_data.get("groupbyRows")),
*get_column_names(form_data.get("groupbyColumns")),
*get_metric_names(form_data.get("metrics")),
+ *(f"%{name}" for name in
get_metric_names(form_data.get("percent_metrics"))),
}
+ # Query exports can already carry display labels rather than selection
names.
+ if verbose_map:
+ expected_columns |= {
+ verbose_map.get(column, column) for column in expected_columns
+ }
if first_column in expected_columns:
Review Comment:
Non-blocking: the allowlist now covers the common keys, but the fallback
still loses the header for any first column that isn't listed. For example,
`{"Category": ..., "Total": ...}` with form data that doesn't mention
`Category` still exports `[blank], Total`. That happens because the
non-MultiIndex flatten branch further down (`processed_df.index = [ ... ]`)
drops the index name. Keeping the name there, e.g. `pd.Index([...],
name=processed_df.index.name)`, makes a wrong guess harmless: `to_excel` then
writes `Category, Total`. That would also cover any form-data keys the
allowlist misses in the future.
Nit (pre-existing): `pd.read_excel` returns numeric headers as numbers. A
dimension named `2024` reads back as the int `2024`, which never matches the
string `"2024"` in `expected_columns`, so its header is still blank. Comparing
`str(first_column)` would fix that.
--
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]