mirror of https://github.com/apache/superset.git
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:
parent
4c522ac65f
commit
865a909690
|
@ -1143,6 +1143,9 @@ class BigNumberViz(BaseViz):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||||
|
if df.empty:
|
||||||
|
return None
|
||||||
|
|
||||||
df = df.pivot_table(
|
df = df.pivot_table(
|
||||||
index=DTTM_ALIAS,
|
index=DTTM_ALIAS,
|
||||||
columns=[],
|
columns=[],
|
||||||
|
@ -1878,6 +1881,9 @@ class WorldMapViz(BaseViz):
|
||||||
return qry
|
return qry
|
||||||
|
|
||||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||||
|
if df.empty:
|
||||||
|
return None
|
||||||
|
|
||||||
from superset.examples import countries
|
from superset.examples import countries
|
||||||
|
|
||||||
fd = self.form_data
|
fd = self.form_data
|
||||||
|
@ -1952,7 +1958,7 @@ class FilterBoxViz(BaseViz):
|
||||||
col = flt.get("column")
|
col = flt.get("column")
|
||||||
metric = flt.get("metric")
|
metric = flt.get("metric")
|
||||||
df = self.dataframes.get(col)
|
df = self.dataframes.get(col)
|
||||||
if df is not None:
|
if df is not None and not df.empty:
|
||||||
if metric:
|
if metric:
|
||||||
df = df.sort_values(
|
df = df.sort_values(
|
||||||
utils.get_metric_name(metric), ascending=flt.get("asc")
|
utils.get_metric_name(metric), ascending=flt.get("asc")
|
||||||
|
@ -1967,6 +1973,8 @@ class FilterBoxViz(BaseViz):
|
||||||
{"id": row[0], "text": row[0]}
|
{"id": row[0], "text": row[0]}
|
||||||
for row in df.itertuples(index=False)
|
for row in df.itertuples(index=False)
|
||||||
]
|
]
|
||||||
|
if not d:
|
||||||
|
return None
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue