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 01:29:23 UTC

[GitHub] [incubator-superset] john-bodley opened a new pull request #9011: [fix] Ensure sunburst column ordering adheres to hierarchy

john-bodley opened a new pull request #9011: [fix] Ensure sunburst column ordering adheres to hierarchy
URL: https://github.com/apache/incubator-superset/pull/9011
 
 
   ### CATEGORY
   
   Choose one
   
   - [x] Bug Fix
   - [ ] Enhancement (new features, refinement)
   - [ ] Refactor
   - [ ] Add tests
   - [ ] Build / Development Environment
   - [ ] Documentation
   
   ### SUMMARY
   
   This PR fixes an issue where the values for the sunburst chart (which takes in a list of list order by the hierarchical columns) were being named incorrectly. The reason being is the resulting `pandas.DataFrame` column ordering is not the same as the ordering defined in the hierarchy. 
   
   The fix is to simply re-order the `pandas.DataFrame` columns to adhere to the column ordering specified in the hierarchy. 
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TEST PLAN
   <!--- What steps should be taken to verify the changes -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [ ] Requires DB Migration.
   - [ ] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ### REVIEWERS
   
   to: @etr2460 @mistercrunch @williaster  

----------------------------------------------------------------
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
serenajiang 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_r370796605
 
 

 ##########
 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:
   `.values.tolist()`?

----------------------------------------------------------------
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


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

Posted by GitBox <gi...@apache.org>.
serenajiang 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_r370794817
 
 

 ##########
 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 []
 
 Review comment:
   ```suggestion
           cols = fd.get("groupby", [])
   ```

----------------------------------------------------------------
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


[GitHub] [incubator-superset] john-bodley merged pull request #9011: [fix] Ensure sunburst column ordering adheres to hierarchy

Posted by GitBox <gi...@apache.org>.
john-bodley merged pull request #9011: [fix] Ensure sunburst column ordering adheres to hierarchy
URL: https://github.com/apache/incubator-superset/pull/9011
 
 
   

----------------------------------------------------------------
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