Skip to content

Commit

Permalink
Merge pull request #8 from biolab/kaplan-meier/domain_models
Browse files Browse the repository at this point in the history
[ENH] owkaplanmeier: stricter DomainModel options
  • Loading branch information
JakaKokosar authored Jan 11, 2021
2 parents 1fe2cd3 + e2324a5 commit 3f02dce
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions orangecontrib/survival_analysis/widgets/owkaplanmeier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from lifelines import KaplanMeierFitter
from lifelines.utils import median_survival_times

from Orange.data import Table, DiscreteVariable, ContinuousVariable
from Orange.data import Table, Domain, DiscreteVariable, ContinuousVariable, TimeVariable
from Orange.widgets import gui
from Orange.widgets.widget import Input, Output, OWWidget, Msg
from Orange.widgets.settings import Setting, ContextSetting, SettingProvider, PerfectDomainContextHandler
Expand Down Expand Up @@ -435,10 +435,22 @@ def set_data(self, data: Table):
if not data:
return

def _filter_domain_model_options(_domain):
vars_ = [var for var in _domain.variables + _domain.metas if not isinstance(var, TimeVariable)]
vars_ = [
var
for var in vars_
if isinstance(var, ContinuousVariable) or isinstance(var, DiscreteVariable) and len(var.values) <= 2
]

return Domain(vars_)

self.data = data
self.controls.time_var.model().set_domain(data.domain)
self.controls.event_var.model().set_domain(data.domain)
domain = _filter_domain_model_options(data.domain)
self.controls.time_var.model().set_domain(domain)
self.controls.event_var.model().set_domain(domain)
self.controls.group_var.model().set_domain(data.domain)

self.time_var = None
self.event_var = None
self.group_var = None
Expand Down

0 comments on commit 3f02dce

Please sign in to comment.