Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdapretnar committed Jun 15, 2022
1 parent aa96555 commit e209e31
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 16 additions & 2 deletions orangecontrib/prototypes/widgets/owsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ def __init__(self, data, attr, delimiter):

column = self.get_string_values(data, self.attr)
values = [s.split(self.delimiter) for s in column]
self.new_values = sorted({val if val else "?" for vals in values for
val in vals})
self.new_values = tuple(sorted({val if val else "?" for vals in
values for val in vals}))

def __eq__(self, other):
return self.attr == other.attr and self.delimiter == \
other.delimiter and self.new_values == other.new_values

def __hash__(self):
return hash((self.attr, self.delimiter, self.new_values))

def __call__(self, data):
column = self.get_string_values(data, self.attr)
Expand All @@ -45,6 +52,13 @@ def __init__(self, fn, new_feature):
super().__init__(fn)
self.new_feature = new_feature

def __eq__(self, other):
return self.compute_shared == other.compute_shared \
and self.new_feature == other.new_feature

def __hash__(self):
return hash((self.compute_shared, self.new_feature))

def compute(self, data, shared_data):
indices = shared_data[self.new_feature]
col = np.zeros(len(data))
Expand Down
16 changes: 15 additions & 1 deletion orangecontrib/prototypes/widgets/tests/test_owsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class TestOWSplit(WidgetTest):
def setUp(self):
self.widget = self.create_widget(OWSplit)
test_path = os.path.dirname(os.path.abspath(__file__))
self.data = Table.from_file(os.path.join(test_path, "orange-in-education.tab"))
self.data = Table.from_file(
os.path.join(test_path, "orange-in-education.tab"))
self._create_simple_corpus()

def _set_attr(self, attr, widget=None):
Expand Down Expand Up @@ -52,6 +53,19 @@ def test_data(self):
output = self.get_output(self.widget.Outputs.data)
self.assertEqual(len(output.domain.attributes),
len(self.data.domain.attributes) + 3)
self.assertTrue("in-class, in hands-on workshops" in output.domain
and "in-class, in lectures" in output.domain and
"outside the classroom" in output.domain)
np.testing.assert_array_equal(output[:10, "in-class, in hands-on "
"workshops"],
np.array([0, 0, 1, 0, 1, 1, 0, 1, 0, 0]
).reshape(-1, 1))
np.testing.assert_array_equal(output[:10, "in-class, in lectures"],
np.array([0, 1, 0, 0, 1, 0, 1, 1, 1, 0]
).reshape(-1, 1))
np.testing.assert_array_equal(output[:10, "outside the classroom"],
np.array([1, 0, 1, 1, 1, 0, 0, 1, 1, 1]
).reshape(-1, 1))

def test_empty_data(self):
"""Do not crash on empty data"""
Expand Down

0 comments on commit e209e31

Please sign in to comment.