Skip to content

Commit

Permalink
Handle empty dataframes in TableViz (#9480)
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: #9468
  • Loading branch information
elukey committed Apr 7, 2020
1 parent 5e53506 commit a52b9ee
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 a52b9ee

Please sign in to comment.