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
This commit is contained in:
Luca Toscano 2020-05-17 07:27:57 +02:00 committed by GitHub
parent ea9b7f2dc4
commit 5ab5457522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -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