This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch 5.0
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b11fd2f22bc7909dd27e4ce376695cbd450081a7
Author: Damian Pendrak <[email protected]>
AuthorDate: Fri Feb 28 16:57:11 2025 +0100

    fix(viz): update nesting logic to handle multiple dimensions in 
PartitionViz (#32290)
    
    (cherry picked from commit 6317a91541ea7251e5455ced09d9b58c34ca0983)
---
 superset/viz.py                      | 10 ++++++++--
 tests/integration_tests/viz_tests.py | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/superset/viz.py b/superset/viz.py
index a42ce94203..f014ce442a 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -2293,10 +2293,16 @@ class PartitionViz(NVD3TimeSeriesViz):
             ]
         if level >= len(levels):
             return []
-        dim_level = levels[level][metric][[dims[0]]]
+
+        dim_level = levels[level][metric]
+        for d in dims:
+            if d not in dim_level:
+                return []
+            dim_level = dim_level[d]
+
         return [
             {
-                "name": i,
+                "name": [*dims, i],
                 "val": dim_level[i],
                 "children": self.nest_values(levels, level + 1, metric, dims + 
[i]),
             }
diff --git a/tests/integration_tests/viz_tests.py 
b/tests/integration_tests/viz_tests.py
index dde6a1dec8..1631f8d7e0 100644
--- a/tests/integration_tests/viz_tests.py
+++ b/tests/integration_tests/viz_tests.py
@@ -442,6 +442,27 @@ class TestPartitionViz(SupersetTestCase):
         assert 1 == len(nest[0]["children"][0]["children"])
         assert 1 == len(nest[0]["children"][0]["children"][0]["children"])
 
+    def test_nest_values_returns_hierarchy_when_more_dimensions(self):
+        raw = {}
+        raw["category"] = ["a", "a", "a"]
+        raw["subcategory"] = ["a.2", "a.1", "a.2"]
+        raw["sub_subcategory"] = ["a.2.1", "a.1.1", "a.2.2"]
+        raw["metric1"] = [5, 10, 15]
+        raw["metric2"] = [50, 100, 150]
+        raw["metric3"] = [500, 1000, 1500]
+        df = pd.DataFrame(raw)
+        test_viz = viz.PartitionViz(Mock(), {})
+        groups = ["category", "subcategory", "sub_subcategory"]
+        levels = test_viz.levels_for("agg_sum", groups, df)
+        nest = test_viz.nest_values(levels)
+        assert 3 == len(nest)
+        for i in range(0, 3):
+            assert "metric" + str(i + 1) == nest[i]["name"]
+        assert 1 == len(nest[0]["children"])
+        assert 2 == len(nest[0]["children"][0]["children"])
+        assert 1 == len(nest[0]["children"][0]["children"][0]["children"])
+        assert 2 == len(nest[0]["children"][0]["children"][1]["children"])
+
     def test_nest_procs_returns_hierarchy(self):
         raw = {}
         raw[DTTM_ALIAS] = [100, 200, 300, 100, 200, 300, 100, 200, 300]

Reply via email to