Skip to content

Commit

Permalink
fix: allow for multiple columns in pivot table report (#17636)
Browse files Browse the repository at this point in the history
* allow for multiple columns in pivot table report

* fix null data issue

* Update tests/unit_tests/charts/test_post_processing.py
  • Loading branch information
eschutho authored Dec 3, 2021
1 parent b5d13d7 commit 13e1929
Show file tree
Hide file tree
Showing 2 changed files with 589 additions and 1 deletion.
7 changes: 6 additions & 1 deletion superset/charts/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def pivot_df( # pylint: disable=too-many-locals, too-many-arguments, too-many-s

# pivot data; we'll compute totals and subtotals later
if rows or columns:
# pivoting with null values will create an empty df
df = df.fillna("NULL")
df = df.pivot_table(
index=rows,
columns=columns,
Expand All @@ -94,7 +96,10 @@ def pivot_df( # pylint: disable=too-many-locals, too-many-arguments, too-many-s
# if no rows were passed the metrics will be in the rows, so we
# need to move them back to columns
if columns and not rows:
df = df.stack().to_frame().T
df = df.stack()
if not isinstance(df, pd.DataFrame):
df = df.to_frame()
df = df.T
df = df[metrics]
df.index = pd.Index([*df.index[:-1], metric_name], name="metric")

Expand Down
Loading

0 comments on commit 13e1929

Please sign in to comment.