Exemple #1
0
 def test_manual_cuts_edit(self):
     widget = self.widget
     data = Table("iris")[::5]
     self.send_signal(self.widget.Inputs.data, data)
     view = widget.varview
     varbg = widget.variable_button_group
     widget.set_default_method(OWDiscretize.Custom)
     widget.default_cutpoints = (0, 2, 4)
     ledit = widget.manual_cuts_edit
     self.assertEqual(ledit.text(), "0, 2, 4")
     ledit.setText("3, 4, 5")
     ledit.editingFinished.emit()
     self.assertEqual(widget.default_cutpoints, (3, 4, 5))
     self.assertEqual(widget._current_default_method(), Custom((3, 4, 5)))
     self.assertTrue(
         all(widget.method_for_index(i) == Default(Custom((3, 4, 5)))
             for i in range(len(data.domain.attributes)))
     )
     select_row(view, 0)
     varbg.button(OWDiscretize.Custom).click()
     ledit = widget.manual_cuts_specific
     ledit.setText("1, 2, 3")
     ledit.editingFinished.emit()
     self.assertEqual(widget.method_for_index(0), Custom((1, 2, 3)))
     ledit.setText("")
     ledit.editingFinished.emit()
     self.assertEqual(widget.method_for_index(0), Custom(()))
Exemple #2
0
 def test_manual_cuts_copy(self):
     widget = self.widget
     data = Table("iris")[::5]
     self.send_signal(self.widget.Inputs.data, data)
     view = widget.varview
     select_row(view, 0)
     varbg = widget.variable_button_group
     varbg.button(OWDiscretize.EqualWidth).click()
     v = widget.discretized_var(0)
     points = tuple(v.compute_value.points)
     cc_button = widget.copy_current_to_manual_button
     cc_button.click()
     self.assertEqual(widget.method_for_index(0), Custom(points))
     self.assertEqual(varbg.checkedId(), OWDiscretize.Custom)
Exemple #3
0
    def test_migration_2_3(self):
        # Obsolete, don't want to cause confusion by public import
        # pylint: disable=import-outside-toplevel
        from Orange.widgets.data.owdiscretize import \
            Default, EqualFreq, Leave, Custom, MDL, EqualWidth, DState
        context_values = {
            'saved_var_states': ({
                (2, 'age'):
                DState(method=Leave()),
                (2, 'rest SBP'):
                DState(method=EqualWidth(k=4)),
                (2, 'cholesterol'):
                DState(method=EqualFreq(k=6)),
                (4, 'max HR'):
                DState(method=Custom(points=(1.0, 2.0, 3.0))),
                (2, 'ST by exercise'):
                DState(method=MDL()),
                (2, 'major vessels colored'):
                DState(method=Default(method=EqualFreq(k=3)))
            }, -2),
            '__version__':
            2
        }

        settings = {
            'autosend': True,
            'controlAreaVisible': True,
            'default_cutpoints': (),
            'default_k': 3,
            'default_method_name': 'EqualFreq',
            '__version__': 2,
            "context_settings": [Context(values=context_values)]
        }

        OWDiscretize.migrate_settings(settings, 2)
        self.assertNotIn("default_method_name", settings)
        self.assertNotIn("default_k", settings)
        self.assertNotIn("default_cutpoints", settings)
        self.assertNotIn("context_settings", settings)
        self.assertEqual(
            settings["var_hints"], {
                None: VarHint(Methods.EqualFreq, (3, )),
                ('ST by exercise', False): VarHint(Methods.MDL, ()),
                ('age', False): VarHint(Methods.Keep, ()),
                ('cholesterol', False): VarHint(Methods.EqualFreq, (6, )),
                ('max HR', True): VarHint(Methods.Custom, (('1, 2, 3'), )),
                ('rest SBP', False): VarHint(Methods.EqualWidth, (4, ))
            })
Exemple #4
0
 def test_delegate(self):
     cases = (
         (DState(Default(Leave()), None, None), ""),
         (DState(Leave(), None, None), "(leave)"),
         (DState(MDL(), [1], None), "(entropy)"),
         (DState(MDL(), [], None), "<removed>"),
         (DState(EqualFreq(2), [1], None), "(equal frequency k=2)"),
         (DState(EqualWidth(2), [1], None), "(equal width k=2)"),
         (DState(Remove(), None, None), "(removed)"),
         (DState(Custom([1]), None, None), "(custom)"),
     )
     delegate = DiscDelegate()
     var = DiscreteVariable("C", ("a", "b"))
     model = VariableListModel()
     model.append(var)
     for state, text in cases:
         model.setData(model.index(0), state, Qt.UserRole)
         option = QStyleOptionViewItem()
         delegate.initStyleOption(option, model.index(0))
         self.assertIn(text, option.text)