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

[bugfix] Fix Tableviz metrics column disorder #5566

Merged

Conversation

yamyamyuo
Copy link
Contributor

@yamyamyuo yamyamyuo commented Aug 4, 2018

Fixes #5373
The cause of metrics disorder in Table View is located in function BaseViz. process_metrics.
This function was introduced from https://github.com/apache/incubator-superset/pull/4914/files

This fix also works for percentage metrics.

@yamyamyuo yamyamyuo changed the title Fix tableviz metrics disorder Fix Tableviz metrics column disorder Aug 4, 2018
@codecov-io
Copy link

codecov-io commented Aug 5, 2018

Codecov Report

Merging #5566 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5566   +/-   ##
=======================================
  Coverage   63.82%   63.82%           
=======================================
  Files         364      364           
  Lines       23059    23059           
  Branches     2568     2568           
=======================================
  Hits        14717    14717           
  Misses       8327     8327           
  Partials       15       15
Impacted Files Coverage Δ
superset/viz.py 81.33% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 135539c...d365e01. Read the comment docs.

@yamyamyuo yamyamyuo changed the title Fix Tableviz metrics column disorder [bugfix] Fix Tableviz metrics column disorder Aug 7, 2018
@SpyderRivera
Copy link
Contributor

Thanks for the fix!

superset/viz.py Outdated
@@ -95,19 +95,21 @@ def __init__(self, datasource, form_data, force=False):
self.process_metrics()

def process_metrics(self):
self.metric_dict = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yamyamyuo yamyamyuo force-pushed the fix_tableviz_metrics_disorder branch from d5e283b to d365e01 Compare August 29, 2018 12:34
@RohitK89
Copy link

@mistercrunch Any idea on a timeline for this PR? This is blocking our users and I hate having to build containers for things if I can just get 'em for free :)

@betodealmeida
Copy link
Member

Merging this because of the unit test, but looks like the fix already made it into master.

@betodealmeida betodealmeida merged commit ab5c910 into apache:master Oct 4, 2018
Copy link
Contributor Author

@yamyamyuo yamyamyuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this because of the unit test, but looks like the fix already made it into master.

thanks! the fix already merged into master by mistercrunch in another PR

superset/viz.py Outdated
self.metric_dict[self.get_metric_label(o)] = o

# Cast to list needed to return serializable object in py3
self.all_metrics = list(self.metric_dict.values())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mistercrunch this is the cause of metrics column disorder in TableViz.
It tries to use self.metric_dict and then converts to list here. I assume that it's going to remove duplicate metrics, since some metrics appear more than once in total which locate in different METRIC_KEYS .

superset/viz.py Outdated
# avoid generating duplicate metrics getting from METRIC_KEYS
if self.get_metric_label(o) not in self.metric_labels:
self.metric_labels.append(self.get_metric_label(o))
self.all_metrics.append(o)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mistercrunch so the best way to avoid duplicate metrics and keep its original order is using list at the beginning.

u'optionName': u'metric_hww53ilkph_jo8b2fyt8rs'},
u'SUM(SP_URB_TOTL)',
u'count']
self.assertEqual(test_viz.all_metrics, expect_all_metrics)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the labels and metrics order is correct.

superset/viz.py Outdated
self.metric_dict = {}
# metrics in TableViz is order sensitive, so metric_dict should be
# OrderedDict
self.metric_dict = OrderedDict()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mistercrunch I have updated this self.metric_dict to OrderedDict() now. Please help to merge this PR.

betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* fix metrics disorder

* add tableviz metric order tests

* lint code

* use OrderedDict to avoid metrics disorder

* fix unit test
@qinzl1
Copy link

qinzl1 commented Apr 11, 2019

pivot_table can not order

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Random column order with Table View
7 participants