Skip to content

[FIX] ZeroDivisionError owmosaic.py#2046

Merged
lanzagar merged 1 commit into
biolab:masterfrom
jerneju:zerodivisionerror-mosaic
Feb 27, 2017
Merged

[FIX] ZeroDivisionError owmosaic.py#2046
lanzagar merged 1 commit into
biolab:masterfrom
jerneju:zerodivisionerror-mosaic

Conversation

@jerneju
Copy link
Copy Markdown
Contributor

@jerneju jerneju commented Feb 22, 2017

Issue

ZeroDivisionError is thrown when invalid data is loaded into widget. For instance: [[0, NaN], [NaN, NaN]].
https://sentry.io/biolab/orange3/issues/204400244/

Description of changes

If the value "total" is zero aborts drawing the plot.

Includes
  • Code changes
  • Tests
  • Documentation

@jerneju
Copy link
Copy Markdown
Contributor Author

jerneju commented Feb 22, 2017

@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 22, 2017

Codecov Report

Merging #2046 into master will decrease coverage by -0.04%.
The diff coverage is 88.88%.

@@            Coverage Diff             @@
##           master    #2046      +/-   ##
==========================================
- Coverage   70.69%   70.66%   -0.04%     
==========================================
  Files         315      315              
  Lines       53900    53834      -66     
==========================================
- Hits        38106    38040      -66     
  Misses      15794    15794

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 67c587e...6026e33. Read the comment docs.


def test_zerodivision_error(self):
"""
ZeroDivisionError should not be thrown when
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you make this description more explicit. Instead of "some kind of invalid data" try to describe what the problem in data was.

try:
self.send_signal("Data", table)
except ZeroDivisionError:
self.assertTrue(False)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

self.fail can be used to make the test fail. And it is also a good idea to specify the reason of the failure ("Widget crashed with ZeroDivisionError" or something like this)

bar_width = self.BAR_WIDTH

def get_counts(attr_vals, values):
if attr_vals == "":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. Could you also add a docstring to this function describing what it does and how it handles zero counts?


def get_counts(attr_vals, values):
if attr_vals == "":
counts = [conditionaldict[val] for val in values]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While draw_data used conditionaldict[val], draw_text used conditionaldict.get(val, 1). Could you elaborate on why indexing is sufficient?

try:
self.send_signal("Data", table)
except ZeroDivisionError:
self.fail("Widget crashed due to ZeroDivisionError.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using data with only NaNs should not result in any kind of error, not just ZeroDivision.
Why not make this test more general: rename from test_zerodivision_error to e.g. test_nan_column, remove the try, all exceptions will be shown when/if they happen.

ZeroDivisionError should not be thrown when a column with only NaN-s is loaded into widget.
https://sentry.io/biolab/orange3/issues/204400244/

Corrects the total value and rectangles' widths.
@lanzagar lanzagar merged commit 7ad7488 into biolab:master Feb 27, 2017
@jerneju jerneju deleted the zerodivisionerror-mosaic branch April 20, 2017 13:47
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.

4 participants