You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/01/24 19:19:05 UTC

[GitHub] [incubator-superset] john-bodley commented on a change in pull request #9011: [fix] Ensure sunburst column ordering adheres to hierarchy

john-bodley commented on a change in pull request #9011: [fix] Ensure sunburst column ordering adheres to hierarchy
URL: https://github.com/apache/incubator-superset/pull/9011#discussion_r370799800
 
 

 ##########
 File path: superset/viz.py
 ##########
 @@ -1601,13 +1601,18 @@ class SunburstViz(BaseViz):
 
     def get_data(self, df: pd.DataFrame) -> VizData:
         fd = self.form_data
-        cols = fd.get("groupby")
+        cols = fd.get("groupby") or []
         metric = utils.get_metric_name(fd.get("metric"))
         secondary_metric = utils.get_metric_name(fd.get("secondary_metric"))
         if metric == secondary_metric or secondary_metric is None:
-            df.columns = cols + ["m1"]  # type: ignore
+            df.rename(columns={df.columns[-1]: "m1"}, inplace=True)
             df["m2"] = df["m1"]
-        return json.loads(df.to_json(orient="values"))
+            cols.extend(["m1", "m2"])
+
+        # Re-order the columns as the query result set column ordering may differ from
+        # that listed in the hierarchy.
+        df = df[cols]
+        return df.to_numpy().tolist()
 
 Review comment:
   @serenajiang per the [documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.values.html#pandas.DataFrame.values) they mention, 
   
   > Warning We recommend using DataFrame.to_numpy() instead.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org