Skip to content

Commit

Permalink
Merge pull request #275 from janezd/fix-text-to-columns-dtype
Browse files Browse the repository at this point in the history
Text to Columns: Fix dtype for empty arrays
  • Loading branch information
janezd committed Feb 8, 2024
2 parents 8a11268 + 1994379 commit 8ec69b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion orangecontrib/prototypes/widgets/owtexttocolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __call__(self, data):
column = data.get_column(self.attr)
values = [{ss.strip() for ss in s.split(self.delimiter)}
for s in column]
return {v: np.array([i for i, xs in enumerate(values) if v in xs])
return {v: np.array([i for i, xs in enumerate(values) if v in xs],
dtype=int)
for v in self.new_values}

def __eq__(self, other):
Expand Down
11 changes: 11 additions & 0 deletions orangecontrib/prototypes/widgets/tests/test_owtexttocolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def test_split_column(self):
np.testing.assert_equal(shared["f o"], [0, 1])
np.testing.assert_equal(shared["o"], [2])

def test_no_known_values(self):
sc = SplitColumn(self.data, self.data.domain.metas[0], ",")
data = Table.from_numpy(
self.data.domain, np.zeros((3, 1)), None,
np.array([["x"] * 2] * 3))
shared = sc(data)
for attr in ("a", "bbb", "d"):
self.assertEqual(shared[attr].size, 0)
oh = OneHotStrings(sc, attr)
np.testing.assert_equal(oh(data), [0, 0, 0])

def test_one_hot_strings(self):
attr = self.data.domain.metas[0]
sc = SplitColumn(self.data, attr, ",")
Expand Down

0 comments on commit 8ec69b9

Please sign in to comment.