-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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] Distances: handling errors due to too large arrays #2315
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2315 +/- ##
==========================================
+ Coverage 73.27% 73.29% +0.01%
==========================================
Files 317 317
Lines 55447 55469 +22
==========================================
+ Hits 40630 40654 +24
+ Misses 14817 14815 -2 |
@astaric, similar code warnings are stupid. See this -- codeclimate complained about two totally different lists of error in |
@@ -48,6 +48,8 @@ class Error(OWWidget.Error): | |||
dense_metric_sparse_data = Msg("Selected metric does not support sparse data") | |||
empty_data = Msg("Empty data set") | |||
mahalanobis_error = Msg("{}") | |||
distances_memory_error = Msg("Not enough memory.") | |||
distances_value_error = Msg("Error occurred while calculating distances: {}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error can be long, so "Error occurred while calculating distances\n{}"
. Skip the colon, so the error looks OK, and the tooltip shows the entire message.
@@ -144,7 +157,7 @@ def compute_distances(self, metric, data): | |||
self.Error.mahalanobis_error(e) | |||
return | |||
|
|||
return metric(data, data, 1 - self.axis, impute=True) | |||
return compute(metric, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A stylistic comment. I don't like the obvious radon fixes --- here's a code that's too complex so let's tear out a chunk of it into a separate function.
The main job of compute_distances
is not to run various checks and fixes, and in the end, yes, call a local function that computes distances.
Turn it around. The "auxiliary" code should be the code that prepares the data and not the code that does the work. So, factor out the preprocessing/checking instead.
|
||
mock = Mock() | ||
mock.side_effect = ValueError | ||
self.widget.compute_distances(mock, self.iris) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use side_effect
as a keyword argument for mock. I wouldn't even bother to have a mock
variable here; I'd use Mock(side_effect=ValueError)
as an argument.
|
||
mock = Mock() | ||
mock.side_effect = MemoryError | ||
self.widget.compute_distances(mock, self.iris) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
Fixed. |
Issue
https://sentry.io/biolab/orange3/issues/196744070/events/5529227746/
Description of changes
Users sees an error message when calculating too large arrays and Orange does not crash.
Includes