diff --git a/unyt/tests/test_units.py b/unyt/tests/test_units.py index 40e1f4d1..35661e78 100644 --- a/unyt/tests/test_units.py +++ b/unyt/tests/test_units.py @@ -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) diff --git a/unyt/unit_object.py b/unyt/unit_object.py index cb93a43c..54c34c1f 100644 --- a/unyt/unit_object.py +++ b/unyt/unit_object.py @@ -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