Skip to content

Commit

Permalink
Handle empty dataframes in TableViz
Browse files Browse the repository at this point in the history
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: apache#9468
  • Loading branch information
elukey committed Apr 6, 2020
1 parent c0807c1 commit 19a4425
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,18 @@ def get_data(self, df: pd.DataFrame) -> VizData:
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))
Expand Down

0 comments on commit 19a4425

Please sign in to comment.