Skip to content

Commit

Permalink
Continuize: Send report
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Dec 23, 2022
1 parent 55da641 commit 3b267e4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Orange/widgets/data/owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,42 @@ def _continuized_vars(self, var, hint=None):
]

def send_report(self):
# TOTO: Implement
pass
if not self.data:
return
single_disc = len(self.disc_view.model()) > 0 \
and len(self.disc_var_hints) == 1 \
and DiscreteOptions[self.disc_var_hints[DefaultKey]].label.lower()
single_cont = len(self.cont_view.model()) > 0 \
and len(self.cont_var_hints) == 1 \
and ContinuousOptions[self.cont_var_hints[DefaultKey]].label.lower()
class_treatment = \
self.data.domain.class_var.is_discrete and \
"As ordinal" if self.continuize_class else "Leave categorical"
if single_disc and single_cont:
self.report_items(
(("Categorical variables", single_disc),
("Numeric variables", single_cont),
("Class variable", class_treatment))
)
else:
if single_disc:
self.report_paragraph("Categorical variables", single_disc)
elif len(self.disc_view.model()) > 0:
self.report_items(
"Categorical variables",
[("Default" if name == DefaultKey else name,
DiscreteOptions[id_].label.lower())
for name, id_ in self.disc_var_hints.items()])
if single_cont:
self.report_paragraph("Numeric varialbes", single_cont)
elif len(self.cont_view.model()) > 0:
self.report_items(
"Numeric variables",
[("Default" if name == DefaultKey else name,
ContinuousOptions[id_].label.lower())
for name, id_ in self.cont_var_hints.items()])
if class_treatment:
self.report_paragraph("Class variable", class_treatment)

@classmethod
def migrate_settings(cls, settings, version):
Expand Down
26 changes: 26 additions & 0 deletions Orange/widgets/data/tests/test_owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,32 @@ def test_transformations(self):
)

def test_send_report(self):
w = self.widget
self.send_signal(w.Inputs.data, Table("heart_disease"))
self.widget.send_report()

w.disc_var_hints[DefaultKey] = Continuize.AsOrdinal
w.disc_var_hints["chest pain"] = w.disc_var_hints["rest ECG"] = Continuize.Remove
w.disc_var_hints["exerc ind ang"] = Continuize.FirstAsBase

self.send_signal(w.Inputs.data, Table("heart_disease"))
self.widget.send_report()

w.cont_var_hints[DefaultKey] = Normalize.Center
w.cont_var_hints["cholesterol"] = Normalize.Scale

self.send_signal(w.Inputs.data, Table("heart_disease"))
self.widget.send_report()

w.continuize_class = True
w.disc_var_hints[DefaultKey] = Continuize.AsOrdinal
w.disc_var_hints["chest pain"] = w.disc_var_hints["rest ECG"] = Continuize.Remove
w.disc_var_hints["exerc ind ang"] = Continuize.FirstAsBase

w.cont_var_hints[DefaultKey] = Normalize.Center
w.cont_var_hints["cholesterol"] = Normalize.Scale

self.send_signal(w.Inputs.data, Table("heart_disease"))
self.widget.send_report()

def test_migrate_settings_to_v3(self):
Expand Down

0 comments on commit 3b267e4

Please sign in to comment.