Skip to content

Adding optional pickle protocol version argument to pandas.to_pickle() #14488

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

Closed
ragesz opened this issue Oct 25, 2016 · 1 comment
Closed

Adding optional pickle protocol version argument to pandas.to_pickle() #14488

ragesz opened this issue Oct 25, 2016 · 1 comment
Labels
API Design Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label
Milestone

Comments

@ragesz
Copy link

ragesz commented Oct 25, 2016

Sometimes pickle files saved in Python v3.x are needed to read in Python v2.x. It would be nice if one can easily set pickle protocol version in to_pickle().

It can be done with the following little changes:

In file /pandas/io/pickle.py:

def to_pickle(obj, path, protocol=pkl.HIGHEST_PROTOCOL):
    """
    Pickle (serialize) object to input file path

    Parameters
    ----------
    obj : any object
    path : string
        File path
    """
    with open(path, 'wb') as f:
        pkl.dump(obj, f, protocol=protocol)

In file /pandas/core/generic.py:

    def to_pickle(self, path, protocol):
        """
        Pickle (serialize) object to input file path.

        Parameters
        ----------
        path : string
            File path
        """
        from pandas.io.pickle import to_pickle
        return to_pickle(self, path, protocol)
@jreback
Copy link
Contributor

jreback commented Oct 25, 2016

sure, you could add this.

@jreback jreback added API Design Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label labels Oct 25, 2016
@jreback jreback added this to the Next Major Release milestone Oct 25, 2016
@jreback jreback modified the milestones: 0.21.0, Next Major Release May 17, 2017
pcluo pushed a commit to pcluo/pandas that referenced this issue May 22, 2017
This PR aims at adding an optional `protocol` parameter to the
function `to_pickle`.   Closes pandas-dev#14488. If needed, I can update the
corresponding test (`pandas/tests/io/test_pickle.py`).

Author: Jean-Baptiste Schiratti <[email protected]>

Closes pandas-dev#16252 from jbschiratti/pickle_protocol and squashes the following commits:

8eb660d [Jean-Baptiste Schiratti] Minor change on whatsnew.
20a854d [Jean-Baptiste Schiratti] Added ref for protocol parameter + edited whatsnew.
14bc485 [Jean-Baptiste Schiratti] Fix : removed unused import.
7631146 [Jean-Baptiste Schiratti] Fix : added issue number.
460ca0c [Jean-Baptiste Schiratti] Shortened paragraph addded in 'whatsnew'.
352220b [Jean-Baptiste Schiratti] Fix : Fixed error message in 'test_read_bad_versions'.
9c9d38f [Jean-Baptiste Schiratti] Added enhancement to 'whatsnew' file.
35f8d18 [Jean-Baptiste Schiratti] Added tests for new 'protocol' parameter in 'to_pickle'.
4bf0386 [Jean-Baptiste Schiratti] Added docstring for negative protocol parameter.
04bc5c2 [Jean-Baptiste Schiratti] Added 'versionadded' tag, improved docstring + fixed import.
66a35e8 [Jean-Baptiste Schiratti] Added 'protocol' parameter to 'to_pickle'.
stangirala pushed a commit to stangirala/pandas that referenced this issue Jun 11, 2017
This PR aims at adding an optional `protocol` parameter to the
function `to_pickle`.   Closes pandas-dev#14488. If needed, I can update the
corresponding test (`pandas/tests/io/test_pickle.py`).

Author: Jean-Baptiste Schiratti <[email protected]>

Closes pandas-dev#16252 from jbschiratti/pickle_protocol and squashes the following commits:

8eb660d [Jean-Baptiste Schiratti] Minor change on whatsnew.
20a854d [Jean-Baptiste Schiratti] Added ref for protocol parameter + edited whatsnew.
14bc485 [Jean-Baptiste Schiratti] Fix : removed unused import.
7631146 [Jean-Baptiste Schiratti] Fix : added issue number.
460ca0c [Jean-Baptiste Schiratti] Shortened paragraph addded in 'whatsnew'.
352220b [Jean-Baptiste Schiratti] Fix : Fixed error message in 'test_read_bad_versions'.
9c9d38f [Jean-Baptiste Schiratti] Added enhancement to 'whatsnew' file.
35f8d18 [Jean-Baptiste Schiratti] Added tests for new 'protocol' parameter in 'to_pickle'.
4bf0386 [Jean-Baptiste Schiratti] Added docstring for negative protocol parameter.
04bc5c2 [Jean-Baptiste Schiratti] Added 'versionadded' tag, improved docstring + fixed import.
66a35e8 [Jean-Baptiste Schiratti] Added 'protocol' parameter to 'to_pickle'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants