|
24 | 24 | from Orange.widgets import gui, report |
25 | 25 | from Orange.widgets.gui import OWComponent |
26 | 26 | from Orange.widgets.settings import Setting, ContextSetting, SettingProvider |
| 27 | +from Orange.widgets.utils.localization import pl |
27 | 28 | from Orange.widgets.utils.plot import variables_selection |
28 | 29 | from Orange.widgets.utils.plot.owplotgui import VariableSelectionModel |
29 | 30 | from Orange.widgets.utils.widgetpreview import WidgetPreview |
@@ -285,6 +286,9 @@ class OWLinearProjection(OWAnchorProjectionWidget): |
285 | 286 | class Error(OWAnchorProjectionWidget.Error): |
286 | 287 | no_cont_features = Msg("Plotting requires numeric features") |
287 | 288 |
|
| 289 | + class Information(OWAnchorProjectionWidget.Information): |
| 290 | + no_lda = Msg("LDA placement is disabled due to unsuitable target.\n{}") |
| 291 | + |
288 | 292 | def _add_controls(self): |
289 | 293 | box = gui.vBox(self.controlArea, box="Features") |
290 | 294 | self._add_controls_variables(box) |
@@ -377,12 +381,27 @@ def _check_options(self): |
377 | 381 | for btn in buttons: |
378 | 382 | btn.setEnabled(True) |
379 | 383 |
|
| 384 | + problem = None |
380 | 385 | if self.data is not None: |
381 | | - has_discrete_class = self.data.domain.has_discrete_class |
382 | | - if not has_discrete_class or len(np.unique(self.data.Y)) < 3: |
383 | | - buttons[Placement.LDA].setEnabled(False) |
384 | | - if self.placement == Placement.LDA: |
385 | | - self.placement = Placement.Circular |
| 386 | + if (class_var := self.data.domain.class_var) is None: |
| 387 | + problem = "Current data has no target variable" |
| 388 | + elif not class_var.is_discrete: |
| 389 | + problem = f"{class_var.name} is not categorical" |
| 390 | + elif (nclasses := len(distinct := np.unique(self.data.Y))) == 0: |
| 391 | + problem = f"Data has no defined values for {class_var.name}" |
| 392 | + elif nclasses < 3: |
| 393 | + vals = " and ".join(f"'{class_var.values[int(i)]}'" for i in distinct) |
| 394 | + problem = \ |
| 395 | + f"Data contains just {['one', 'two'][nclasses - 1]} distinct " \ |
| 396 | + f"{pl(nclasses, 'value')} ({vals}) for '{class_var.name}'; " \ |
| 397 | + "at least three are required." |
| 398 | + if problem is None: |
| 399 | + self.Information.no_lda.clear() |
| 400 | + else: |
| 401 | + self.Information.no_lda(problem) |
| 402 | + buttons[Placement.LDA].setEnabled(False) |
| 403 | + if self.placement == Placement.LDA: |
| 404 | + self.placement = Placement.Circular |
386 | 405 |
|
387 | 406 | self.controls.graph.hide_radius.setEnabled( |
388 | 407 | self.placement != Placement.Circular) |
|
0 commit comments