villebro commented on a change in pull request #11615:
URL:
https://github.com/apache/incubator-superset/pull/11615#discussion_r520466482
##########
File path: tests/viz_tests.py
##########
@@ -1384,3 +1384,92 @@ def test_format_datetime_from_invalid_string(self):
def test_format_datetime_from_int(self):
assert viz.PivotTableViz._format_datetime(123) == 123
assert viz.PivotTableViz._format_datetime(123.0) == 123.0
+
+
+class TestTreemapViz(SupersetTestCase):
+ def test_nest2(self):
+ datasource = self.get_datasource_mock()
+ form_data = {}
+ test_viz = viz.TreemapViz(datasource, form_data)
+ df = pd.DataFrame(
+ {"a": [1, 2, 3, 4, 5, 6, 7, 8]},
+ index=[[1, 1, 1, 1, 2, 2, 2, 2], [11, 11, 12, 12, 21, 21, 22, 22]],
+ )
+ result = test_viz._nest(metric="a", df=df)
+ expected = [
+ {
+ "name": 1,
+ "children": [
+ {"name": 11, "value": 1},
+ {"name": 11, "value": 2},
+ {"name": 12, "value": 3},
+ {"name": 12, "value": 4},
+ ],
+ },
+ {
+ "name": 2,
+ "children": [
+ {"name": 21, "value": 5},
+ {"name": 21, "value": 6},
+ {"name": 22, "value": 7},
+ {"name": 22, "value": 8},
+ ],
+ },
+ ]
+ self.assertEqual(result, expected)
+
+ def test_nest3(self):
+ datasource = self.get_datasource_mock()
+ form_data = {}
+ test_viz = viz.TreemapViz(datasource, form_data)
+ df = pd.DataFrame(
+ {"a": [1, 2, 3, 4, 5, 6, 7, 8]},
+ index=[
+ [1, 1, 1, 1, 2, 2, 2, 2],
+ [11, 11, 12, 12, 21, 21, 22, 22],
+ [111, 112, 121, 122, 211, 212, 221, 222],
+ ],
+ )
+ # Before fixing, this line will raise a keyerror
Review comment:
nit: comment not needed after the fix is merged.
```suggestion
```
----------------------------------------------------------------
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]