Skip to content

bpo-36018: Make __pos__ return a distinct instance of NormDist #12009

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

Merged
merged 1 commit into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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