villebro commented on a change in pull request #12417:
URL: https://github.com/apache/superset/pull/12417#discussion_r561699562
##########
File path: tests/viz_tests.py
##########
@@ -531,6 +531,92 @@ def test_column_nulls(self):
]
self.assertEqual(expected, data)
+ def test_column_metrics_in_order(self):
+ form_data = {
+ "metrics": ["z_column", "votes", "a_column"],
+ "adhoc_filters": [],
+ "groupby": ["toppings"],
+ "columns": [],
+ }
+ datasource = self.get_datasource_mock()
+ df = pd.DataFrame(
+ {
+ "toppings": ["cheese", "pepperoni", "cheese", "pepperoni"],
+ "role": ["engineer", "engineer", None, None],
+ "votes": [3, 5, 1, 2],
+ "a_column": [3, 5, 1, 2],
+ "z_column": [3, 5, 1, 2],
+ }
+ )
+ test_viz = viz.DistributionBarViz(datasource, form_data)
+ data = test_viz.get_data(df)
+
+ expected = [
+ {
+ "key": "z_column",
+ "values": [{"x": "pepperoni", "y": 3.5}, {"x": "cheese", "y":
2.0}],
+ },
+ {
+ "key": "votes",
+ "values": [{"x": "pepperoni", "y": 3.5}, {"x": "cheese", "y":
2.0}],
+ },
+ {
+ "key": "a_column",
+ "values": [{"x": "pepperoni", "y": 3.5}, {"x": "cheese", "y":
2.0}],
+ },
+ ]
+
+ self.assertEqual(expected, data)
+
+ def test_column_metrics_in_order_with_breakdowns(self):
+ form_data = {
+ "metrics": ["z_column", "votes", "a_column"],
+ "adhoc_filters": [],
+ "groupby": ["toppings"],
+ "columns": ["role"],
+ }
+ datasource = self.get_datasource_mock()
+ df = pd.DataFrame(
+ {
+ "toppings": ["cheese", "pepperoni", "cheese", "pepperoni"],
+ "role": ["engineer", "engineer", None, None],
+ "votes": [3, 5, 1, 2],
+ "a_column": [3, 5, 1, 2],
+ "z_column": [3, 5, 1, 2],
+ }
+ )
+ test_viz = viz.DistributionBarViz(datasource, form_data)
+ data = test_viz.get_data(df)
+
+ expected = [
+ {
+ "key": "z_column, {}".format(NULL_STRING),
+ "values": [{"x": "pepperoni", "y": 2}, {"x": "cheese", "y":
1}],
+ },
+ {
+ "key": "z_column, engineer",
+ "values": [{"x": "pepperoni", "y": 5}, {"x": "cheese", "y":
3}],
+ },
+ {
+ "key": "votes, {}".format(NULL_STRING),
+ "values": [{"x": "pepperoni", "y": 2}, {"x": "cheese", "y":
1}],
+ },
+ {
+ "key": "votes, engineer",
+ "values": [{"x": "pepperoni", "y": 5}, {"x": "cheese", "y":
3}],
+ },
+ {
+ "key": "a_column, {}".format(NULL_STRING),
+ "values": [{"x": "pepperoni", "y": 2}, {"x": "cheese", "y":
1}],
+ },
+ {
+ "key": "a_column, engineer",
+ "values": [{"x": "pepperoni", "y": 5}, {"x": "cheese", "y":
3}],
+ },
+ ]
Review comment:
nit: let's use f-strings here
```suggestion
expected = [
{
"key": f"z_column, {NULL_STRING}",
"values": [{"x": "pepperoni", "y": 2}, {"x": "cheese", "y":
1}],
},
{
"key": "z_column, engineer",
"values": [{"x": "pepperoni", "y": 5}, {"x": "cheese", "y":
3}],
},
{
"key": f"votes, {NULL_STRING}",
"values": [{"x": "pepperoni", "y": 2}, {"x": "cheese", "y":
1}],
},
{
"key": "votes, engineer",
"values": [{"x": "pepperoni", "y": 5}, {"x": "cheese", "y":
3}],
},
{
"key": f"a_column, {NULL_STRING}",
"values": [{"x": "pepperoni", "y": 2}, {"x": "cheese", "y":
1}],
},
{
"key": "a_column, engineer",
"values": [{"x": "pepperoni", "y": 5}, {"x": "cheese", "y":
3}],
},
]
```
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]