[FIX] Distances: handling errors due to too large arrays#2315
[FIX] Distances: handling errors due to too large arrays#2315janezd merged 2 commits intobiolab:masterfrom jerneju:value-distances
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 |
| 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.
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.
| return | ||
|
|
||
| return metric(data, data, 1 - self.axis, impute=True) | ||
| return compute(metric, data) |
There was a problem hiding this comment.
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.
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) |
|
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