Skip to content

Commit

Permalink
fix: pandas bug when data is blank on post-processing (apache#20629)
Browse files Browse the repository at this point in the history
* fix pandas bug when data is blank on post-processing

* account for multiple queries when data is blank
  • Loading branch information
eschutho authored and akshatsri committed Jul 19, 2022
1 parent e203241 commit 2d33c2f
Show file tree
Hide file tree
Showing 2 changed files with 605 additions and 3 deletions.
9 changes: 7 additions & 2 deletions superset/charts/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,17 @@ def apply_post_process(
post_processor = post_processors[viz_type]

for query in result["queries"]:
if query["result_format"] not in (rf.value for rf in ChartDataResultFormat):
raise Exception(f"Result format {query['result_format']} not supported")

if not query["data"]:
# do not try to process empty data
continue

if query["result_format"] == ChartDataResultFormat.JSON:
df = pd.DataFrame.from_dict(query["data"])
elif query["result_format"] == ChartDataResultFormat.CSV:
df = pd.read_csv(StringIO(query["data"]))
else:
raise Exception(f"Result format {query['result_format']} not supported")

processed_df = post_processor(df, form_data, datasource)

Expand Down
Loading

0 comments on commit 2d33c2f

Please sign in to comment.