You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2021/08/19 16:39:21 UTC

[superset] branch master updated: fix: columns/index rebuild (#16355)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 37f09bd  fix: columns/index rebuild (#16355)
37f09bd is described below

commit 37f09bd2963f248ba8a92d56a062acc96472e058
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Aug 19 09:38:24 2021 -0700

    fix: columns/index rebuild (#16355)
---
 superset/charts/post_processing.py | 4 +++-
 superset/utils/csv.py              | 8 ++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/superset/charts/post_processing.py b/superset/charts/post_processing.py
index 9ef976b..3ad0a85 100644
--- a/superset/charts/post_processing.py
+++ b/superset/charts/post_processing.py
@@ -296,7 +296,9 @@ def apply_post_process(
         query["coltypes"] = extract_dataframe_dtypes(processed_df)
         query["rowcount"] = len(processed_df.index)
 
-        # flatten columns/index so we can encode data as JSON
+        # Flatten hierarchical columns/index since they are represented as
+        # `Tuple[str]`. Otherwise encoding to JSON later will fail because
+        # maps cannot have tuples as their keys in JSON.
         processed_df.columns = [
             " ".join(str(name) for name in column).strip()
             if isinstance(column, tuple)
diff --git a/superset/utils/csv.py b/superset/utils/csv.py
index 3c362f7..42d2c55 100644
--- a/superset/utils/csv.py
+++ b/superset/utils/csv.py
@@ -96,10 +96,14 @@ def get_chart_dataframe(
 
     result = simplejson.loads(content.decode("utf-8"))
     df = pd.DataFrame.from_dict(result["result"][0]["data"])
+
+    # rebuild hierarchical columns and index
     df.columns = pd.MultiIndex.from_tuples(
-        tuple(colname) for colname in result["result"][0]["colnames"]
+        tuple(colname) if isinstance(colname, list) else (colname,)
+        for colname in result["result"][0]["colnames"]
     )
     df.index = pd.MultiIndex.from_tuples(
-        tuple(indexname) for indexname in result["result"][0]["indexnames"]
+        tuple(indexname) if isinstance(indexname, list) else (indexname,)
+        for indexname in result["result"][0]["indexnames"]
     )
     return df