innovark37 commented on code in PR #40885:
URL: https://github.com/apache/superset/pull/40885#discussion_r3601562002
##########
superset/charts/client_processing.py:
##########
@@ -310,6 +310,33 @@ def table(
}
+def _is_default_index_column(series: pd.Series) -> bool:
+ return series.tolist() == list(range(len(series)))
+
+
+def _read_excel_for_client_processing(
+ data: bytes,
+ form_data: dict[str, Any],
+) -> pd.DataFrame:
+ df = pd.read_excel(BytesIO(data))
+ if len(df.columns) == 0:
+ return df
+
+ first_column = df.columns[0]
+ expected_columns = {
+ *get_column_names(form_data.get("columns")),
+ *get_metric_names(form_data.get("metrics")),
+ }
+
+ if first_column in expected_columns:
+ return df
+
+ if _is_default_index_column(df.iloc[:, 0]):
+ return df.iloc[:, 1:].reset_index(drop=True)
+
+ return df.set_index(first_column)
Review Comment:
Good catch, thanks. This was a valid edge case for pivot_table_v2 exports.
I updated the XLSX re-import expected-column detection to include
`groupbyRows` and `groupbyColumns` in addition to `columns` and `metrics`, so
real pivot dimensions are not mistaken for an export-added index column. I also
added a regression test covering XLSX client processing for pivot tables with
row/column groupbys.
--
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]