Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: columns/index rebuild #16355

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion superset/charts/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ def apply_post_process(
query["coltypes"] = extract_dataframe_dtypes(processed_df)
query["rowcount"] = len(processed_df.index)

# flatten columns/index so we can encode data as JSON
# Flatten hierarchical columns/index since they are represented as
# `Tuple[str]`. Otherwise encoding to JSON later will fail because
# maps cannot have tuples as their keys in JSON.
processed_df.columns = [
" ".join(str(name) for name in column).strip()
if isinstance(column, tuple)
Expand Down
8 changes: 6 additions & 2 deletions superset/utils/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ def get_chart_dataframe(

result = simplejson.loads(content.decode("utf-8"))
df = pd.DataFrame.from_dict(result["result"][0]["data"])

# rebuild hierarchical columns and index
df.columns = pd.MultiIndex.from_tuples(
tuple(colname) for colname in result["result"][0]["colnames"]
tuple(colname) if isinstance(colname, list) else (colname,)
for colname in result["result"][0]["colnames"]
)
df.index = pd.MultiIndex.from_tuples(
tuple(indexname) for indexname in result["result"][0]["indexnames"]
tuple(indexname) if isinstance(indexname, list) else (indexname,)
for indexname in result["result"][0]["indexnames"]
)
return df