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

Reverse map discrete options using identity #305

Merged
merged 8 commits into from Mar 14, 2019
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 14, 2019

Using a dictionary to map options from their value to their label did not work well because the values may be non-hashable or hash inconsistently. Instead this PR switches to using the value's identity to do the reverse mapping which should work reliably.

@jsignell
Copy link
Member

@jsignell jsignell commented Mar 14, 2019

This seems like a more straightforward approach. Are there downsides? Is it slower?

@jbednar
Copy link
Member

@jbednar jbednar commented Mar 14, 2019

Sounds good. Should Param do the same for selectors?

@philippjfr
Copy link
Member Author

@philippjfr philippjfr commented Mar 14, 2019

I doubt it's much slower, if anything I'd expect it to be cheaper not to do the hashing. That said the approach isn't quite right since __contains__ will fall back to testing for equality which will break for certain types (e.g. numpy arrays). I'll have to add a small is_in utility.

panel/widgets/player.py Outdated Show resolved Hide resolved
@philippjfr
Copy link
Member Author

@philippjfr philippjfr commented Mar 14, 2019

Sounds good. Should Param do the same for selectors?

Yes, the named_objs implementation in param seems to suffer from the same issues.

@codecov-io
Copy link

@codecov-io codecov-io commented Mar 14, 2019

Codecov Report

Merging #305 into master will decrease coverage by 0.06%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #305      +/-   ##
==========================================
- Coverage    89.3%   89.24%   -0.07%     
==========================================
  Files          63       63              
  Lines        6528     6565      +37     
==========================================
+ Hits         5830     5859      +29     
- Misses        698      706       +8
Impacted Files Coverage Δ
panel/widgets/player.py 86.27% <100%> (ø) ⬆️
panel/tests/test_widgets.py 100% <100%> (ø) ⬆️
panel/util.py 70.25% <85.71%> (-2.6%) ⬇️
panel/widgets/select.py 89.51% <92.5%> (-0.41%) ⬇️

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 e8f8533...8dc09d2. Read the comment docs.

Copy link
Member

@jsignell jsignell left a comment

LGTM

@philippjfr philippjfr merged commit 2a4ccc7 into master Mar 14, 2019
3 checks passed
@philippjfr philippjfr deleted the reverse_map_options branch Sep 9, 2019
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.

None yet

4 participants