Skip to content

Commit

Permalink
Removal of Variable.make: Fix a few anonymous variables
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Jul 7, 2019
1 parent 4cc1f3e commit 5283234
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Orange/data/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def __str__(self):
def __getstate__(self):
state = self.__dict__.copy()
state.pop("_known_domains", None)
state.pop("_last_conversion")
state["_last_conversion"] = None
return state

def __setstate__(self, state):
Expand Down
2 changes: 1 addition & 1 deletion Orange/tests/test_evaluation_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def compute_auc(self, actual, predicted):
probabilities[0, :, 1] = predicted[0]
probabilities[0, :, 0] = 1 - predicted[0]
results = Results(
nmethods=1, domain=Domain([], [DiscreteVariable(values='01')]),
nmethods=1, domain=Domain([], [DiscreteVariable("x", values='01')]),
actual=actual, predicted=predicted)
results.probabilities = probabilities
return AUC(results)[0]
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/data/owdatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ def __init__(self, future, watcher, pb):

def variable_icon(name):
if name == "categorical":
return gui.attributeIconDict[Orange.data.DiscreteVariable()]
return gui.attributeIconDict[Orange.data.DiscreteVariable("x")]
elif name == "numeric": # ??
return gui.attributeIconDict[Orange.data.ContinuousVariable()]
return gui.attributeIconDict[Orange.data.ContinuousVariable("x")]
else:
return gui.attributeIconDict[-1]

Expand Down
6 changes: 3 additions & 3 deletions Orange/widgets/data/owfeatureconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def editorData(self):


_VarMap = {
DiscreteDescriptor: vartype(Orange.data.DiscreteVariable()),
ContinuousDescriptor: vartype(Orange.data.ContinuousVariable()),
StringDescriptor: vartype(Orange.data.StringVariable())
DiscreteDescriptor: vartype(Orange.data.DiscreteVariable("d")),
ContinuousDescriptor: vartype(Orange.data.ContinuousVariable("c")),
StringDescriptor: vartype(Orange.data.StringVariable("s"))
}


Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/data/owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def is_valid_item(self, setting, condition, attrs, metas):

def encode_setting(self, context, setting, value):
if setting.name == 'conditions':
CONTINUOUS = vartype(ContinuousVariable())
CONTINUOUS = vartype(ContinuousVariable("x"))
for i, (attr, op, values) in enumerate(value):
if context.attributes.get(attr) == CONTINUOUS:
if values and isinstance(values[0], str):
Expand Down
10 changes: 5 additions & 5 deletions Orange/widgets/data/tests/test_owcreateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_map_by_substring(self):
map_by_substring(self.arr, [], False, False))))

def test_value_from_string_substring(self):
trans = ValueFromStringSubstring(StringVariable(), self.patterns)
trans = ValueFromStringSubstring(StringVariable("x"), self.patterns)
arr2 = np.hstack((self.arr.astype(object), [None]))

with patch('Orange.widgets.data.owcreateclass.map_by_substring') as mbs:
Expand All @@ -66,7 +66,7 @@ def test_value_from_string_substring(self):
[0, 1, 2, 0, 3, np.nan])

def test_value_string_substring_flags(self):
trans = ValueFromStringSubstring(StringVariable(), self.patterns)
trans = ValueFromStringSubstring(StringVariable("x"), self.patterns)
with patch('Orange.widgets.data.owcreateclass.map_by_substring') as mbs:
trans.case_sensitive = True
trans.transform(self.arr)
Expand All @@ -83,12 +83,12 @@ def test_value_string_substring_flags(self):

def test_value_from_discrete_substring(self):
trans = ValueFromDiscreteSubstring(
DiscreteVariable(values=self.arr), self.patterns)
DiscreteVariable("x", values=self.arr), self.patterns)
np.testing.assert_equal(trans.lookup_table, [0, 1, 2, 0, 3])

def test_value_from_discrete_substring_flags(self):
trans = ValueFromDiscreteSubstring(
DiscreteVariable(values=self.arr), self.patterns)
DiscreteVariable("x", values=self.arr), self.patterns)
with patch('Orange.widgets.data.owcreateclass.map_by_substring') as mbs:
trans.case_sensitive = True
a, patterns, case_sensitive, match_beginning = mbs.call_args[0]
Expand All @@ -106,7 +106,7 @@ def test_value_from_discrete_substring_flags(self):
self.assertTrue(match_beginning)

arr2 = self.arr[::-1]
trans.variable = DiscreteVariable(values=arr2)
trans.variable = DiscreteVariable("x", values=arr2)
a, patterns, case_sensitive, match_beginning = mbs.call_args[0]
np.testing.assert_equal(a, arr2)
self.assertEqual(patterns, self.patterns)
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/data/tests/test_owselectcolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from Orange.widgets.data.owrank import OWRank
from Orange.widgets.widget import AttributeList

Continuous = vartype(ContinuousVariable())
Discrete = vartype(DiscreteVariable())
Continuous = vartype(ContinuousVariable("c"))
Discrete = vartype(DiscreteVariable("d"))


class TestSelectAttributesDomainContextHandler(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/evaluate/tests/test_owtestlearners.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_testOnTest_incompatible_domain(self):
self.widget.resampling = OWTestLearners.TestOnTest
# test data with the same class (otherwise the widget shows a different error)
# and a non-nan X
iris_test = iris.transform(Domain([ContinuousVariable()],
iris_test = iris.transform(Domain([ContinuousVariable("x")],
class_vars=iris.domain.class_vars))
iris_test.X[:, 0] = 1
self.send_signal(self.widget.Inputs.test_data, iris_test)
Expand Down
8 changes: 4 additions & 4 deletions Orange/widgets/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def createAttributePixmap(char, background=Qt.black, color=Qt.white):
class __AttributeIconDict(dict):
def __getitem__(self, key):
if not self:
for tpe, char, col in ((vartype(ContinuousVariable()),
for tpe, char, col in ((vartype(ContinuousVariable("c")),
"N", (202, 0, 32)),
(vartype(DiscreteVariable()),
(vartype(DiscreteVariable("d")),
"C", (26, 150, 65)),
(vartype(StringVariable()),
(vartype(StringVariable("s")),
"S", (0, 0, 0)),
(vartype(TimeVariable()),
(vartype(TimeVariable("t")),
"T", (68, 170, 255)),
(-1, "?", (128, 128, 128))):
self[tpe] = createAttributePixmap(char, QtGui.QColor(*col))
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/tests/test_class_values_context_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from Orange.widgets.settings import ContextSetting, ClassValuesContextHandler
from Orange.widgets.utils import vartype

Continuous = vartype(ContinuousVariable())
Discrete = vartype(DiscreteVariable())
Continuous = vartype(ContinuousVariable("x"))
Discrete = vartype(DiscreteVariable("x"))


class TestClassValuesContextHandler(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/tests/test_domain_context_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from Orange.widgets.settings import DomainContextHandler, ContextSetting
from Orange.widgets.utils import vartype

Continuous = 100 + vartype(ContinuousVariable())
Discrete = 100 + vartype(DiscreteVariable())
Continuous = 100 + vartype(ContinuousVariable("x"))
Discrete = 100 + vartype(DiscreteVariable("x"))


class TestDomainContextHandler(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/tests/test_perfect_domain_context_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from Orange.widgets.settings import ContextSetting, PerfectDomainContextHandler, Context, Setting
from Orange.widgets.utils import vartype

Continuous = vartype(ContinuousVariable())
Discrete = vartype(DiscreteVariable())
Continuous = vartype(ContinuousVariable("x"))
Discrete = vartype(DiscreteVariable("x"))


class TestPerfectDomainContextHandler(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/visualize/tests/test_owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_empty_clusters(self):
"""Test if empty clusters are not displayed and warning is shown"""
data = np.array([1, 1, 1, 2, 2, 2, 3, 3, 3])

table = Table.from_numpy(Domain([ContinuousVariable()]),
table = Table.from_numpy(Domain([ContinuousVariable("y")]),
data.reshape((9, 1)))
self.widget.controls.merge_kmeans.setChecked(True)

Expand All @@ -156,7 +156,7 @@ def test_use_enough_colors(self):
# Before 201906 thresholds modified the palette and decreased
# the number of colors used.
data = np.arange(1000).reshape(-1, 1)
table = Table.from_numpy(Domain([ContinuousVariable()]), data)
table = Table.from_numpy(Domain([ContinuousVariable("y")]), data)
self.send_signal(self.widget.Inputs.data, table)
self.widget.threshold_high = 0.05
self.widget.update_color_schema()
Expand Down

0 comments on commit 5283234

Please sign in to comment.