Skip to content

Commit

Permalink
Continuize: Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Mar 30, 2023
1 parent b74bdc7 commit 6d757e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
16 changes: 6 additions & 10 deletions Orange/widgets/data/owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ def create(title, vartype, methods):
for box in boxes:
box.setFixedWidth(width)

box = self.class_box = gui.hBox(self.mainArea)

box = gui.hBox(self.mainArea)
gui.button(
box, self, "Reset All", callback=self._on_reset_hints,
Expand Down Expand Up @@ -467,12 +465,6 @@ def setData(self, data):
domain = data.domain if data else None
self.disc_view.model().set_domain(domain)
self.cont_view.model().set_domain(domain)
self.disc_box.setVisible(
domain is None or domain.has_discrete_attributes(include_metas=True))
self.cont_box.setVisible(
domain is None or domain.has_continuous_attributes(include_metas=True))
self.class_box.setVisible(
domain is None or domain.has_discrete_class)
if data:
# Clean up hints only when receiving new data, not on disconnection
self._set_hints()
Expand Down Expand Up @@ -538,6 +530,10 @@ def _unsupported_sparse(self):
domain = self.data.domain
disc = set()
cont = set()
# At the time of writing, self.data.Y cannot be sparse (setter for
# `Y` converts it to dense, as done in
# https://github.com/biolab/orange3/commit/a18f38059caf37f3b329d6ad688189561959bb24)
# Including it here doesn't hurt, though.
for part, attrs in ((self.data.X, domain.attributes),
(self.data.Y, domain.class_vars),
(self.data.metas, domain.metas)):
Expand All @@ -546,7 +542,7 @@ def _unsupported_sparse(self):
for var in attrs
if var.is_discrete}
cont |= {self._hint_for_var(var)
for var in domain.attributes
for var in attrs
if type(var) is ContinuousVariable}
disc &= {method.id_
for method in DiscreteOptions.values()
Expand Down Expand Up @@ -587,7 +583,7 @@ def most_frequent(col):

def is_attr(self, var):
domain = self.data.domain
return domain.index(var) < len(domain.attributes)
return 0 <= domain.index(var) < len(domain.attributes)

def default_for_var(self, var):
if self.is_attr(var):
Expand Down
22 changes: 4 additions & 18 deletions Orange/widgets/data/tests/test_owcontinuize.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring,unsubscriptable-object,protected-access
import unittest
from itertools import chain
from unittest.mock import Mock, patch

import numpy as np
from AnyQt.QtCore import Qt, QModelIndex, QItemSelectionModel
from AnyQt.QtTest import QSignalSpy

from orangewidget.tests.base import GuiTest

from Orange.data import Table, DiscreteVariable, ContinuousVariable, Domain
from Orange.widgets.data.owcontinuize import OWContinuize, DefaultKey, \
ContinuousOptions, Normalize, Continuize, DiscreteOptions, ContDomainModel, \
DefaultContModel, ListViewSearch
ContinuousOptions, Normalize, Continuize, DiscreteOptions, \
ContDomainModel, DefaultContModel, ListViewSearch
from Orange.widgets.tests.base import WidgetTest
from orangewidget.utils.itemmodels import SeparatedListDelegate

Expand Down Expand Up @@ -43,11 +45,6 @@ def test_continuous(self):
self.widget.commit.now()

def test_one_column_equal_values(self):
"""
No crash on a column with equal values and with selected option
normalize by standard deviation.
GH-2144
"""
table = Table("iris")
table = table[:, 1].copy()
with table.unlocked():
Expand All @@ -58,12 +55,6 @@ def test_one_column_equal_values(self):
self.widget.commit.now()

def test_one_column_nan_values_normalize_sd(self):
"""
No crash on a column with NaN values and with selected option
normalize by standard deviation (Not the same issue which is
tested above).
GH-2144
"""
table = Table("iris")
with table.unlocked():
table[:, 2] = np.NaN
Expand All @@ -79,11 +70,6 @@ def test_one_column_nan_values_normalize_sd(self):
self.widget.commit.now()

def test_one_column_nan_values_normalize_span(self):
"""
No crash on a column with NaN values and with selected option
normalize by span.
GH-2144
"""
table = Table("iris")
with table.unlocked():
table[:, 2] = np.NaN
Expand Down

0 comments on commit 6d757e5

Please sign in to comment.