classification
Title: Implementation-depended pickling floats with protocol 0
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: alexandre.vassalotti, pitrou, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-12-21 08:10 by serhiy.storchaka, last changed 2015-02-15 12:35 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
pickle_float_repr.patch serhiy.storchaka, 2015-02-08 08:56 review
Messages (6)
msg232992 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-21 08:10
Python and C implementations of pickle produce different results when pickle floats with protocol 0.

>>> pickle.dumps(4.2, 0)
b'F4.2000000000000002\n.'
>>> pickle._dumps(4.2, 0)
b'F4.2\n.'
msg232995 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-21 08:58
Python implementation uses repr(value) and C implementation uses '%.17g' % value.
msg233024 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2014-12-22 20:13
The repr for floats was changed some time ago to use a shorter decimal strings when possible. Both representations should yield the same float value once decoded. If we want to make the C and Python implementations of pickle consistent, then we should pick on what the Python version does currently: i.e., call repr on the float.
msg233027 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-12-22 22:58
This looks less like a bug than an enhancement request.
msg235550 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-08 08:56
Here is a patch.
msg236034 - (view) Author: Roundup Robot (python-dev) Date: 2015-02-15 12:34
New changeset 8c9121993eb5 by Serhiy Storchaka in branch 'default':
Issue #23096: Pickle representation of floats with protocol 0 now is the same
https://hg.python.org/cpython/rev/8c9121993eb5
History
Date User Action Args
2015-02-15 12:35:43serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-02-15 12:34:41python-devsetnosy: + python-dev
messages: + msg236034
2015-02-15 12:07:42serhiy.storchakasetassignee: serhiy.storchaka
2015-02-08 08:56:57serhiy.storchakasetfiles: + pickle_float_repr.patch
versions: - Python 2.7, Python 3.4
messages: + msg235550

keywords: + patch
stage: patch review
2014-12-22 22:58:17pitrousetmessages: + msg233027
2014-12-22 20:13:36alexandre.vassalottisetmessages: + msg233024
2014-12-21 08:58:21serhiy.storchakasetmessages: + msg232995
2014-12-21 08:10:33serhiy.storchakacreate