Skip to content

Commit

Permalink
Merge pull request yt-project#114 from saethlin/master
Browse files Browse the repository at this point in the history
Fix unit hash function
  • Loading branch information
ngoldbaum authored Dec 30, 2019
2 parents e7b198d + 6d81f73 commit a2645f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions unyt/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,14 @@ def test_percent():

assert a == c
assert c == d


def test_equal_has_same_hash():
a = Unit("m")
b = Unit("m")
c = Unit("m*s/s")

assert a == b
assert b == c
assert hash(a) == hash(b)
assert hash(b) == hash(c)
2 changes: 1 addition & 1 deletion unyt/unit_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def units(self):
return self

def __hash__(self):
return super(Unit, self).__hash__()
return hash(self.registry.unit_system_id) ^ hash(self.expr)

# end sympy conventions

Expand Down

0 comments on commit a2645f8

Please sign in to comment.