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] Correspondence: Prevent crashing when cont attr has one value #2149

Merged
merged 4 commits into from
Apr 21, 2017
Merged

[FIX] Correspondence: Prevent crashing when cont attr has one value #2149

merged 4 commits into from
Apr 21, 2017

Conversation

jerneju
Copy link
Contributor

@jerneju jerneju commented Mar 29, 2017

Issue

Widget crashes on discrete attributes with only one value.
https://sentry.io/biolab/orange3/issues/243133261/

Description of changes

Check if there is a second value.

Includes
  • Code changes
  • Tests
  • Documentation

@jerneju
Copy link
Contributor Author

jerneju commented Mar 29, 2017

@codecov-io
Copy link

codecov-io commented Mar 29, 2017

Codecov Report

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

@@            Coverage Diff             @@
##           master    #2149      +/-   ##
==========================================
+ Coverage   67.78%   67.83%   +0.05%     
==========================================
  Files         319      319              
  Lines       54940    54962      +22     
==========================================
+ Hits        37240    37284      +44     
+ Misses      17700    17678      -22

list(zip(
["0", "0", "0"]
)))
self.send_signal("Data", table)
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool trick. You will get the same results with list(zip("000")).

However, [('0',)]*3 or simply [(0,), (0,), (0,)] or np.zeros((3, 1)) would be more reader-friendly.

self.component_x, self.component_y = 0, 1
self.component_x = 0
self.component_y = 1 if \
len(self.varlist[self.selected_var_indices[-1]].values) > 1 else 0
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need len here.

(I'd actually write self.component_y = bool(self.varlist[self.selected_var_indices[-1]].values), but basically just to annoy @astaric. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

He does need len, because he wants to check if it is >1 and not >0.
It is also harder to annoy @astaric, but the if ... else is unnecessary, so:
self.component_y = len(self.varlist[self.selected_var_indices[-1]].values) > 1
or if someone is the strict type:
int(len(self.varlist[self.selected_var_indices[-1]].values) > 1)

@lanzagar lanzagar self-assigned this Apr 7, 2017
Copy link
Contributor

@lanzagar lanzagar left a comment

Choose a reason for hiding this comment

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

I still get strange behaviour and crashes when data has a variable with a single value.
I used titanic and feature constructor to add a constant discrete var.

@@ -350,6 +351,9 @@ def gsvd(M, Wu, Wv):
F = numpy.c_[D_r] * U * D
G = numpy.c_[D_c] * V.T * D

if F.shape == (1, 1) and F == numpy.array([[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 had to read this twice... Why not if F.shape == (1, 1) and F[0, 0] == 0? Simpler and less work for all. Also, F[0, 0] = 1 below. Sorry for overlooking this before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@jerneju jerneju changed the title [FIX] Correspondence: Prevent crashing when cont attr has one value [WIP][FIX] Correspondence: Prevent crashing when cont attr has one value Apr 14, 2017
@jerneju
Copy link
Contributor Author

jerneju commented Apr 19, 2017

Fixed.

@jerneju jerneju changed the title [WIP][FIX] Correspondence: Prevent crashing when cont attr has one value [FIX] Correspondence: Prevent crashing when cont attr has one value Apr 20, 2017
@lanzagar
Copy link
Contributor

Seems to be broken.
Try titanic data set and show first two features (compare with master).

@lanzagar lanzagar merged commit 4924983 into biolab:master Apr 21, 2017
@jerneju jerneju deleted the index-corresondence branch April 21, 2017 13:20
@jerneju
Copy link
Contributor Author

jerneju commented Jun 28, 2017

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