You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2020/04/07 17:37:16 UTC

[incubator-superset] branch master updated: Handle empty dataframes in TableViz (#9480)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a52b9ee  Handle empty dataframes in TableViz (#9480)
a52b9ee is described below

commit a52b9ee8fffb123d98e111c26ca82714deae49de
Author: Luca Toscano <el...@users.noreply.github.com>
AuthorDate: Tue Apr 7 19:37:03 2020 +0200

    Handle empty dataframes in TableViz (#9480)
    
    TableViz fails to display empty dataframes returning an error like:
    "None of [Index(['project', 'count'], dtype='object')] are in the [columns]"
    
    The behavior has been observed while testing 0.36.0rc3 with
    Druid datasources.
    
    issue: #9468
---
 superset/viz.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/superset/viz.py b/superset/viz.py
index 5a9a6ac..f17f234 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -625,17 +625,18 @@ class TableViz(BaseViz):
             self.form_data.get("percent_metrics") or []
         )
 
-        df = pd.concat(
-            [
-                df[non_percent_metric_columns],
-                (
-                    df[percent_metric_columns]
-                    .div(df[percent_metric_columns].sum())
-                    .add_prefix("%")
-                ),
-            ],
-            axis=1,
-        )
+        if not df.empty:
+            df = pd.concat(
+                [
+                    df[non_percent_metric_columns],
+                    (
+                        df[percent_metric_columns]
+                        .div(df[percent_metric_columns].sum())
+                        .add_prefix("%")
+                    ),
+                ],
+                axis=1,
+            )
 
         data = self.handle_js_int_overflow(
             dict(records=df.to_dict(orient="records"), columns=list(df.columns))