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

Split: whitespace and empty space #256

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 6 additions & 4 deletions orangecontrib/prototypes/widgets/owsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __init__(self, data, attr, delimiter):
self.delimiter = delimiter

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

Expand All @@ -32,9 +33,10 @@ def __hash__(self):

def __call__(self, data):
column = self.get_string_values(data, self.attr)
values = [set(s.split(self.delimiter)) for s in column]
shared_data = {v: [i for i, xs in enumerate(values) if v in xs] for v
in self.new_values}
values = [{t.strip() for t in s.split(self.delimiter)}
for s in column]
shared_data = {v: [i for i, xs in enumerate(values) if v in xs]
for v in self.new_values}
return shared_data

@staticmethod
Expand Down
9 changes: 5 additions & 4 deletions orangecontrib/prototypes/widgets/tests/test_owsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _create_simple_corpus(self) -> None:
[
["foo,"],
["bar,baz "],
["foo,bar"],
["foo, bar"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bar with leading space must be the same as bar without.

[""],
]
)
Expand Down Expand Up @@ -99,9 +99,10 @@ def test_empty_split(self):
variable name."""
self.widget.delimiter = ","
self.send_signal(self.widget.Inputs.data, self.small_table)
# new columns will be ["?", "bar", "baz ", "foo (1)"]
self.assertEqual(len(self.get_output(self.widget.Outputs.data).domain),
5)
out = self.get_output(self.widget.Outputs.data)
self.assertEqual(
{var.name for var in out.domain.attributes},
{"bar", "baz", "foo (1)"})


if __name__ == "__main__":
Expand Down