Skip to content
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

Implementation-depended pickling floats with protocol 0 #67285

Closed
serhiy-storchaka opened this issue Dec 21, 2014 · 6 comments
Closed

Implementation-depended pickling floats with protocol 0 #67285

serhiy-storchaka opened this issue Dec 21, 2014 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 23096
Nosy @pitrou, @avassalotti, @serhiy-storchaka
Files
  • pickle_float_repr.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-02-15.12:35:43.683>
    created_at = <Date 2014-12-21.08:10:33.232>
    labels = ['type-bug', 'library']
    title = 'Implementation-depended pickling floats with protocol 0'
    updated_at = <Date 2015-02-15.12:35:43.683>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-02-15.12:35:43.683>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-02-15.12:35:43.683>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-12-21.08:10:33.232>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['38039']
    hgrepos = []
    issue_num = 23096
    keywords = ['patch']
    message_count = 6.0
    messages = ['232992', '232995', '233024', '233027', '235550', '236034']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'alexandre.vassalotti', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23096'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    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.'

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 21, 2014
    @serhiy-storchaka
    Copy link
    Member Author

    Python implementation uses repr(value) and C implementation uses '%.17g' % value.

    @avassalotti
    Copy link
    Member

    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.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 22, 2014

    This looks less like a bug than an enhancement request.

    @serhiy-storchaka
    Copy link
    Member Author

    Here is a patch.

    @serhiy-storchaka serhiy-storchaka self-assigned this Feb 15, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 15, 2015

    New changeset 8c9121993eb5 by Serhiy Storchaka in branch 'default':
    Issue bpo-23096: Pickle representation of floats with protocol 0 now is the same
    https://hg.python.org/cpython/rev/8c9121993eb5

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants