Commit 5eabec02 authored by Raymond Hettinger's avatar Raymond Hettinger Committed by GitHub

bpo-38521: Fix error in NormalDist.__eq__() (GH-16840)

parent ecb035cd
......@@ -1092,7 +1092,7 @@ class NormalDist:
"Two NormalDist objects are equal if their mu and sigma are both equal."
if not isinstance(x2, NormalDist):
return NotImplemented
return (x1._mu, x2._sigma) == (x2._mu, x2._sigma)
return x1._mu == x2._mu and x1._sigma == x2._sigma
def __hash__(self):
"NormalDist objects hash equal if their mu and sigma are both equal."
......
......@@ -2651,9 +2651,13 @@ class TestNormalDist:
nd2 = NormalDist(2, 4)
nd3 = NormalDist()
nd4 = NormalDist(2, 4)
nd5 = NormalDist(2, 8)
nd6 = NormalDist(8, 4)
self.assertNotEqual(nd1, nd2)
self.assertEqual(nd1, nd3)
self.assertEqual(nd2, nd4)
self.assertNotEqual(nd2, nd5)
self.assertNotEqual(nd2, nd6)
# Test NotImplemented when types are different
class A:
......
Fixed erroneous equality comparison in statistics.NormalDist().
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment