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] OWMosaic: Fix crash for empty column #2006

Merged
merged 3 commits into from
Feb 24, 2017

Conversation

rokgomiscek
Copy link
Contributor

Issue

Widget crashes if the columns are empty.
To reproduce: Connect data to Select Columns. Remove features, target variable and meta attributes. Connect to Mosaic Display.

Description of changes

Added an extra check in in set_data().

Includes
  • Code changes
  • Tests
  • Documentation

@@ -400,7 +400,7 @@ def set_data(self, data):
self.closeContext()
self.data = data
self.init_combos(self.data)
if self.data is None or not len(self.data):
if self.data is None or not len(self.data) or not len(self.data[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to test this on domain, not data.

Besides, meta attributes are useful only if they are discrete or continuous, not strings. I think you should check this, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

def test_empty_column(self):
"""Check that the widget doesn't crash if the columns are empty"""
self.send_signal("Data", self.data[:,:0])

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test with a single string meta attribute.

@codecov-io
Copy link

codecov-io commented Feb 17, 2017

Codecov Report

Merging #2006 into master will increase coverage by 0.05%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master   #2006      +/-   ##
=========================================
+ Coverage   70.65%   70.7%   +0.05%     
=========================================
  Files         315     343      +28     
  Lines       53828   54484     +656     
=========================================
+ Hits        38034   38525     +491     
- Misses      15794   15959     +165

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24abbb4...9ff33e0. Read the comment docs.

def test_string_meta(self):
"""Check widget for dataset with only one string meta"""
domain = Domain([], metas=[StringVariable("m")])
data = Table(domain, np.arange(6).reshape(6, 1)[:, :0],
Copy link
Contributor

@lanzagar lanzagar Feb 17, 2017

Choose a reason for hiding this comment

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

Is np.arange(6).reshape(6, 1)[:, :0] supposed to produce np.empty((6, 0)) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.... changed :)

@@ -400,7 +400,8 @@ def set_data(self, data):
self.closeContext()
self.data = data
self.init_combos(self.data)
if self.data is None or not len(self.data):
if self.data is None or not len(self.data) or not \
any(attr.is_discrete or attr.is_continuous for attr in chain(data.domain, data.domain.metas)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Lint says line too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broke the line.

@@ -26,6 +26,10 @@ def test_no_data(self):
"""Check that the widget doesn't crash on empty data"""
self.send_signal("Data", self.data[:0])

def test_empty_column(self):
"""Check that the widget doesn't crash if the columns are empty"""
self.send_signal("Data", self.data[:,:0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Lint would like one space after commas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added space.

@lanzagar lanzagar modified the milestone: 3.3.12 Feb 17, 2017
@astaric astaric modified the milestones: future, 3.3.12 Feb 20, 2017
@lanzagar
Copy link
Contributor

Lint is still not happy...
Can you fix the 3 minor aesthetic issues so we can merge with all green.
I am partly responsible for the missing space after comma in np.empty - I edited the comment, but you copied it too quickly ;)
The other two are indentation issues - pycharm should auto-indent correctly.

@rokgomiscek
Copy link
Contributor Author

Better? :)

@@ -400,7 +400,10 @@ def set_data(self, data):
self.closeContext()
self.data = data
self.init_combos(self.data)
if self.data is None or not len(self.data):
if (self.data is None or
Copy link
Member

Choose a reason for hiding this comment

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

Almost there :) Now radon is complaining that this function (which was not exactly a diamond before) looks worse.

I tend to agree, as the data checking part of code is growing larger and larger. I would recommend extraction the whole if-elif-else block into a method called something like "_get_discrete_data" that gets the data and returns data that consists only of discrete variables. The whole block would then turn into self.discrete_data = self._get_discrete_data(data)

+points if the new method has a docstring :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the block to a new method (with a docstring).

@lanzagar lanzagar merged commit dcdf39a into biolab:master Feb 24, 2017
@astaric astaric modified the milestone: future Apr 19, 2017
@rokgomiscek rokgomiscek deleted the mosaic_no_features branch February 23, 2018 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants