mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
GH-99155: Fix NormalDist
pickle with 0
and 1
protocols (GH99156)
This commit is contained in:
parent
f626b7b504
commit
bef9efabc3
3 changed files with 15 additions and 3 deletions
|
@ -1446,3 +1446,9 @@ class NormalDist:
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'{type(self).__name__}(mu={self._mu!r}, sigma={self._sigma!r})'
|
return f'{type(self).__name__}(mu={self._mu!r}, sigma={self._sigma!r})'
|
||||||
|
|
||||||
|
def __getstate__(self):
|
||||||
|
return self._mu, self._sigma
|
||||||
|
|
||||||
|
def __setstate__(self, state):
|
||||||
|
self._mu, self._sigma = state
|
||||||
|
|
|
@ -3003,14 +3003,19 @@ class TestNormalDist:
|
||||||
nd = NormalDist(100, 15)
|
nd = NormalDist(100, 15)
|
||||||
self.assertNotEqual(nd, lnd)
|
self.assertNotEqual(nd, lnd)
|
||||||
|
|
||||||
def test_pickle_and_copy(self):
|
def test_copy(self):
|
||||||
nd = self.module.NormalDist(37.5, 5.625)
|
nd = self.module.NormalDist(37.5, 5.625)
|
||||||
nd1 = copy.copy(nd)
|
nd1 = copy.copy(nd)
|
||||||
self.assertEqual(nd, nd1)
|
self.assertEqual(nd, nd1)
|
||||||
nd2 = copy.deepcopy(nd)
|
nd2 = copy.deepcopy(nd)
|
||||||
self.assertEqual(nd, nd2)
|
self.assertEqual(nd, nd2)
|
||||||
nd3 = pickle.loads(pickle.dumps(nd))
|
|
||||||
self.assertEqual(nd, nd3)
|
def test_pickle(self):
|
||||||
|
nd = self.module.NormalDist(37.5, 5.625)
|
||||||
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
with self.subTest(proto=proto):
|
||||||
|
pickled = pickle.loads(pickle.dumps(nd, protocol=proto))
|
||||||
|
self.assertEqual(nd, pickled)
|
||||||
|
|
||||||
def test_hashability(self):
|
def test_hashability(self):
|
||||||
ND = self.module.NormalDist
|
ND = self.module.NormalDist
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix :class:`statistics.NormalDist` pickle with ``0`` and ``1`` protocols.
|
Loading…
Add table
Add a link
Reference in a new issue