Skip to content

Commit

Permalink
perf(postprocessing): improve pivot postprocessing operation (#23465)
Browse files Browse the repository at this point in the history
Co-authored-by: Usiel Riedl <usiel.riedl@automattic.com>
  • Loading branch information
Usiel and Usiel committed Mar 24, 2023
1 parent d1947f7 commit be2eb31
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions superset/utils/pandas_postprocessing/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def pivot( # pylint: disable=too-many-arguments,too-many-locals
if not drop_missing_columns and columns:
for row in df[columns].itertuples():
for metric in aggfunc.keys():
series_set.add(str(tuple([metric]) + tuple(row[1:])))
series_set.add(tuple([metric]) + tuple(row[1:]))

df = df.pivot_table(
values=aggfunc.keys(),
Expand All @@ -101,10 +101,7 @@ def pivot( # pylint: disable=too-many-arguments,too-many-locals
)

if not drop_missing_columns and len(series_set) > 0 and not df.empty:
for col in df.columns:
series = str(col)
if series not in series_set:
df = df.drop(col, axis=PandasAxis.COLUMN)
df = df.drop(df.columns.difference(series_set), axis=PandasAxis.COLUMN)

if combine_value_with_metric:
df = df.stack(0).unstack()
Expand Down

0 comments on commit be2eb31

Please sign in to comment.