Skip to content

Commit e1af2d8

Browse files
OWFeatureStatistics: Fix crash when switching to data set with no target variable
1 parent 19eec22 commit e1af2d8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Orange/widgets/data/owfeaturestatistics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ def set_data(self, data):
776776

777777
if data is not None:
778778
self.color_var_model.set_domain(data.domain)
779+
self.color_var = None
779780
if self.data.domain.class_vars:
780781
self.color_var = self.data.domain.class_vars[0]
781782
else:

Orange/widgets/data/tests/test_owfeaturestatistics.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,30 @@ def test_on_data_with_discrete_with_no_values(self, prepare_table):
264264
self.force_render_table()
265265
self.run_through_variables()
266266

267+
def test_switching_to_dataset_with_no_target_var(self):
268+
"""Switching from data set with target variable to a data set with
269+
no target variable should not result in crash."""
270+
data1 = make_table([continuous_full, ints_full], [ints_same, rgb_same])
271+
data2 = make_table([rgb_full, ints_full])
272+
273+
self.send_signal(self.widget.Inputs.data, data1)
274+
self.force_render_table()
275+
276+
self.send_signal(self.widget.Inputs.data, data2)
277+
self.force_render_table()
278+
279+
def test_switching_to_dataset_with_target_var(self):
280+
"""Switching from data set with no target variable to a data set with
281+
a target variable should not result in crash."""
282+
data1 = make_table([rgb_full, ints_full])
283+
data2 = make_table([continuous_full, ints_full], [ints_same, rgb_same])
284+
285+
self.send_signal(self.widget.Inputs.data, data1)
286+
self.force_render_table()
287+
288+
self.send_signal(self.widget.Inputs.data, data2)
289+
self.force_render_table()
290+
267291

268292
def select_rows(rows: List[int], widget: OWFeatureStatistics):
269293
"""Since the widget sorts the rows, selecting rows isn't trivial."""

0 commit comments

Comments
 (0)