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

[FIX] Select Rows: None on output when no data #2726

Merged
merged 2 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions Orange/widgets/data/owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,11 @@ def commit(self):
matching_output = remover(matching_output)
non_matching_output = remover(non_matching_output)

self.Outputs.matching_data.send(matching_output)
self.Outputs.unmatched_data.send(non_matching_output)
def output_filter(output):
return output if output is not None and len(output) else None
Copy link
Contributor

Choose a reason for hiding this comment

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

I here agree with @astaric's usual comment about my code. If-else expressions in Python are mostly unreadable. I'd prefer

if output is not None and len(output):
    return output

You don't even need return None here, but you may add it to make it explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, besides, I don't like the function at all. I'd prefer having

if not len(matching_output):
    matching_output = None

and the same for non_matching_output.

The same amount of code, but way more explicit.


self.Outputs.matching_data.send(output_filter(matching_output))
self.Outputs.unmatched_data.send(output_filter(non_matching_output))

self.match_desc = report.describe_data_brief(matching_output)
self.nonmatch_desc = report.describe_data_brief(non_matching_output)
Expand Down
17 changes: 17 additions & 0 deletions Orange/widgets/data/tests/test_owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,20 @@ def widget_with_context(self, domain, conditions):
settings = dict(context_settings=[context])

return self.create_widget(OWSelectRows, settings)

def test_output_filter(self):
"""
None on output when there is no data.
GH-2726
"""
data = Table("iris")[:10]
len_data = len(data)
self.send_signal(self.widget.Inputs.data, data)

self.enterFilter(data.domain[0], "is below", "-1")
self.assertIsNone(self.get_output("Matching Data"))
self.assertEqual(len(self.get_output("Unmatched Data")), len_data)
self.widget.remove_all_button.click()
self.enterFilter(data.domain[0], "is below", "10")
self.assertIsNone(self.get_output("Unmatched Data"))
self.assertEqual(len(self.get_output("Matching Data")), len_data)