Skip to content

Commit 57d4ecc

Browse files
OWPythagoreanTree: Fix depth limit not being restored properly from context
1 parent dd8b66b commit 57d4ecc

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

Orange/widgets/visualize/owpythagorastree.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,24 @@ def set_tree(self, model=None):
172172

173173
self._update_main_area()
174174

175-
# The target class can also be passed from the meta properties
176-
# This must be set after `_update_target_class_combo`
177-
if hasattr(model, 'meta_target_class_index'):
178-
self.target_class_index = model.meta_target_class_index
179-
self.update_colors()
180-
181-
# Get meta variables describing what the settings should look like
182-
# if the tree is passed from the Pythagorean forest widget.
183-
if hasattr(model, 'meta_size_calc_idx'):
184-
self.size_calc_idx = model.meta_size_calc_idx
185-
self.update_size_calc()
186-
187-
# TODO There is still something wrong with this
188-
# if hasattr(model, 'meta_depth_limit'):
189-
# self.depth_limit = model.meta_depth_limit
190-
# self.update_depth()
191-
192175
self.openContext(self.model)
193176

177+
self.update_depth()
178+
179+
# The forest widget sets the following attributes on the tree,
180+
# describing the settings on the forest widget. To keep the tree
181+
# looking the same as on the forest widget, we prefer these settings to
182+
# context settings, if set.
183+
if hasattr(model, "meta_target_class_index"):
184+
self.target_class_index = model.meta_target_class_index
185+
self.update_colors()
186+
if hasattr(model, "meta_size_calc_idx"):
187+
self.size_calc_idx = model.meta_size_calc_idx
188+
self.update_size_calc()
189+
if hasattr(model, "meta_depth_limit"):
190+
self.depth_limit = model.meta_depth_limit
191+
self.update_depth()
192+
194193
self.Outputs.annotated_data.send(create_annotated_table(self.data, None))
195194

196195
def clear(self):

Orange/widgets/visualize/tests/test_owpythagorastree.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,15 @@ def test_forest_tree_table(self):
383383
square.setSelected(True)
384384
tab = self.get_output(tree_w.Outputs.selected_data, widget=tree_w)
385385
self.assertGreater(len(tab), 0)
386+
387+
def test_changing_data_restores_depth_from_previous_settings(self):
388+
titanic_data = Table("titanic")[::50]
389+
forest = RandomForestLearner(n_estimators=3)(titanic_data)
390+
forest.instances = titanic_data
391+
392+
self.send_signal(self.widget.Inputs.tree, forest.trees[0])
393+
self.widget.controls.depth_limit.setValue(1)
394+
395+
# The domain is still the same, so restore the depth limit from before
396+
self.send_signal(self.widget.Inputs.tree, forest.trees[1])
397+
self.assertEqual(self.widget.ptree._depth_limit, 1)

0 commit comments

Comments
 (0)