Skip to content

[FIX] Variable: Prevent hashing of Values of DiscreteVariable.#3217

Merged
astaric merged 3 commits intobiolab:masterfrom
thocevar:valuehash
Aug 31, 2018
Merged

[FIX] Variable: Prevent hashing of Values of DiscreteVariable.#3217
astaric merged 3 commits intobiolab:masterfrom
thocevar:valuehash

Conversation

@thocevar
Copy link
Contributor

@thocevar thocevar commented Aug 31, 2018

Issue

Values of StringVariable are hashed incorrectly (fixes #2912).

Values of DiscreteVariable are impossible to hash as dictated by the __eq__ function. For example:

from Orange.data.variable import *
val = Value(DiscreteVariable("var", ["red","green","blue"]), 1)
print(val == 1, hash(val) == hash(1))  # True True
print(val == "green", hash(val) == hash("green"))  # True False
Description of changes

As we can not make hash(1) == hash("green"), we prevent hashing of Values of DiscreteVariables with an exception. Users should hash directly ids or domain values instead.

This might break things that use dictionaries or sets of Values. However, the tests didn't discover any such cases.

Includes
  • Code changes
  • Tests
  • Documentation

@thocevar thocevar changed the title Variable: Prevent hashing of Values of DiscreteVariable. [FIX] Variable: Prevent hashing of Values of DiscreteVariable. Aug 31, 2018
@codecov-io
Copy link

Codecov Report

Merging #3217 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master   #3217      +/-   ##
=========================================
+ Coverage    82.8%   82.8%   +<.01%     
=========================================
  Files         346     346              
  Lines       59601   59603       +2     
=========================================
+ Hits        49350   49355       +5     
+ Misses      10251   10248       -3

@astaric astaric merged commit 7857c4b into biolab:master Aug 31, 2018
@lanzagar lanzagar added this to the 3.16 milestone Sep 7, 2018
@brunap
Copy link

brunap commented Sep 13, 2018

Lan, this change disables plotting in Biopharm add-on: ProcessPlot widget.

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.

Value.__hash__ is wrong

5 participants