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

Make AffineScalarFunc hashable for Pandas, Pint and Pint-Pandas #170

Closed
4 changes: 4 additions & 0 deletions uncertainties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,10 @@ def std_dev(self):
# Abbreviation (for formulas, etc.):
s = std_dev

def __hash__(self):
# Placeholder until we figure out how to really make these hashable
return id(self)

Choose a reason for hiding this comment

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

will this satisfy the invariance x == y \Rightarrow hash(x) == hash(y)?

Copy link
Author

Choose a reason for hiding this comment

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

I ran some tests:

u = ufloat(1, 2)
v = ufloat(1, 2)
w = u+u
z = w / 2

# u != v, expected
# u == z, expected
# id(u) != id(v) != id(z)

a = float(1+2)
b = float(2+1)
c = a+a
d = c/2

# a == b, expected
# a == d, expected
# b == d, expected
# id(a) != id(b) != id(d)

I'll see what I can come up with to satisfy the invariant. Thanks!


def __repr__(self):
# Not putting spaces around "+/-" helps with arrays of
# Variable, as each value with an uncertainty is a
Expand Down