EnxDev commented on code in PR #43718:
URL: https://github.com/apache/superset/pull/43718#discussion_r3903194546
##########
superset/charts/client_processing.py:
##########
@@ -216,14 +677,59 @@ def pivot_df( # pylint: disable=too-many-locals,
too-many-arguments, too-many-s
subtotal_values = subtotal_values.apply(
pd.to_numeric, errors="coerce"
)
- subtotal = pivot_v2_aggfunc_map[aggfunc](subtotal_values,
axis=0)
+ if percent_mode:
+ subtotal = subtotal_values.apply(
+ lambda series: _reduce(series,
collapse(series.to_frame())[1])
+ )
+ else:
+ subtotal = pivot_v2_aggfunc_map[aggfunc](subtotal_values,
axis=0)
depth = groups.nlevels - len(subgroup) - 1
total = metric_name if level == 0 else __("Subtotal")
subtotal.name = tuple([*subgroup, total, *([""] * depth)]) #
noqa: C409
# insert row after subgroup
df = pd.concat(
[df[: slice_.stop], subtotal.to_frame().T, df[slice_.stop
:]]
)
+ inserted_rows.append(subtotal.name)
+ row_prefix_depth[subtotal.name] = level
+
+ if percent_mode and rollup_levels:
+ df = _apply_rollup_totals(
+ df,
+ rows,
+ columns,
+ metrics,
+ rollup_levels,
+ totals_metric_level,
+ row_prefix_depth,
+ column_prefix_depth,
+ )
+
+ if percent_mode:
+ df = _apply_show_values_as(
+ df,
+ percent_mode,
+ axis,
+ metrics,
+ combine_metrics,
+ inserted_rows,
+ inserted_columns,
+ reducers,
+ _rollup_denominators(
+ df,
+ percent_mode,
+ rows,
+ columns,
+ metrics,
+ rollup_levels or {},
+ totals_metric_level,
+ row_prefix_depth,
+ column_prefix_depth,
+ apply_metrics_on_rows,
Review Comment:
Could we also swap `show_rows_total` and `show_columns_total` when metrics
are moved to rows? The final `df.T` flips the totals inserted above: with
`metricsLayout: ROWS`, `rowTotals: true`, and `colTotals: false`, the export
gets bottom total rows but no right-hand Total column (4×1 instead of the
chart's 2×2 with `grouping_sets_df`). Testing each toggle separately should
cover this.
--
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]