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

DimensionlessFloat is not hashable #380

Open
kylinzzx opened this issue Aug 3, 2021 · 1 comment
Open

DimensionlessFloat is not hashable #380

kylinzzx opened this issue Aug 3, 2021 · 1 comment

Comments

@kylinzzx
Copy link
Contributor

kylinzzx commented Aug 3, 2021

DimensionlessFloat can not be called by hash(obj)
I am not sure this is a designed behavior.

import labrad.units as U
a = U.Value(3, 'ns')
type(a['ns'])  # float
hash(a['ns'])  # no error, float number is hashable.

b = U.Value(3, 'ns')
c = U.Value(1, 'GHz')
print(type(b*c))  # DimensionlessFloat
print(hash(b*c))  
# Type Error  
# unhashable type: 'DimensionlessFloat'
@fanmingyu212
Copy link
Contributor

One way to solve this problem might be implementing __hash__ method in the WithDimensionlessUnit class (

class WithDimensionlessUnit(object):
). Currently the method is only implemented in the WithUnit class.

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

No branches or pull requests

2 participants