Skip to content

Commit

Permalink
bpo-36018: Make __pos__ return a distinct instance of NormDist (pytho…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored and miss-islington committed Feb 24, 2019
1 parent e895de3 commit 79fbcc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def __truediv__(x1, x2):
return NormalDist(x1.mu / x2, x1.sigma / fabs(x2))

def __pos__(x1):
return x1
return NormalDist(x1.mu, x1.sigma)

def __neg__(x1):
return NormalDist(-x1.mu, x1.sigma)
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,18 @@ def test_cdf(self):
with self.assertRaises(statistics.StatisticsError):
Y.cdf(90)

def test_unary_operations(self):
NormalDist = statistics.NormalDist
X = NormalDist(100, 12)
Y = +X
self.assertIsNot(X, Y)
self.assertEqual(X.mu, Y.mu)
self.assertEqual(X.sigma, Y.sigma)
Y = -X
self.assertIsNot(X, Y)
self.assertEqual(X.mu, -Y.mu)
self.assertEqual(X.sigma, Y.sigma)

def test_same_type_addition_and_subtraction(self):
NormalDist = statistics.NormalDist
X = NormalDist(100, 12)
Expand Down

0 comments on commit 79fbcc5

Please sign in to comment.