Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text to Columns: Fix dtype for empty arrays #275

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading