You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by er...@apache.org on 2020/05/17 05:28:22 UTC

[incubator-superset] branch master updated: FilterBox, BigNumber, WorldMap: Handle empty results - second attempt (#9789)

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

erikrit 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 5ab5457  FilterBox,BigNumber,WorldMap: Handle empty results - second attempt (#9789)
5ab5457 is described below

commit 5ab5457522a141139958a52c88e021c3e5a50ad7
Author: Luca Toscano <el...@users.noreply.github.com>
AuthorDate: Sun May 17 07:27:57 2020 +0200

    FilterBox,BigNumber,WorldMap: Handle empty results - second attempt (#9789)
    
    * FilteBox: handle empty results (second attempt)
    
    This change was originally attempted in #9671 but reverted
    since it broke FilterBox charts with only a time selector.
    
    After some tests I reworked the patch to avoid returning None,
    but instead returning an empty list for each col/selector with
    an empty dataframe associated. This allows to see all the selectors
    without any breakage.
    
    * BigNumberViz: avoid user facing errors when the dataframe is empty
    
    * WorldMapViz: avoid user facing errors when the dataframe is empty
---
 superset/viz.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/superset/viz.py b/superset/viz.py
index 0ed3e30..cc5a89a 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1133,6 +1133,9 @@ class BigNumberViz(BaseViz):
         return d
 
     def get_data(self, df: pd.DataFrame) -> VizData:
+        if df.empty:
+            return None
+
         df = df.pivot_table(
             index=DTTM_ALIAS,
             columns=[],
@@ -1868,6 +1871,9 @@ class WorldMapViz(BaseViz):
         return qry
 
     def get_data(self, df: pd.DataFrame) -> VizData:
+        if df.empty:
+            return None
+
         from superset.examples import countries
 
         fd = self.form_data
@@ -1942,7 +1948,7 @@ class FilterBoxViz(BaseViz):
             col = flt.get("column")
             metric = flt.get("metric")
             df = self.dataframes.get(col)
-            if df is not None:
+            if df is not None and not df.empty:
                 if metric:
                     df = df.sort_values(
                         utils.get_metric_name(metric), ascending=flt.get("asc")
@@ -1957,6 +1963,8 @@ class FilterBoxViz(BaseViz):
                         {"id": row[0], "text": row[0]}
                         for row in df.itertuples(index=False)
                     ]
+            else:
+                df[col] = []
         return d