FilterBox,BigNumber,WorldMap: Handle empty results (#9671)

This change avoids Pandas errors to pop up in chart when no data
is returned (confusing users). In this way a nicer
"No Results etc.." is returned.
This commit is contained in:
Luca Toscano 2020-05-04 20:03:23 +02:00 committed by GitHub
parent 4c522ac65f
commit 865a909690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -1143,6 +1143,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=[],
@ -1878,6 +1881,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
@ -1952,7 +1958,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")
@ -1967,6 +1973,8 @@ class FilterBoxViz(BaseViz):
{"id": row[0], "text": row[0]}
for row in df.itertuples(index=False)
]
if not d:
return None
return d