-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Adding 'protocol' parameter to 'to_pickle'. #16252
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
Conversation
tests are the first thing you should write. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs some tests. with valid & invalid protocol passed.
pandas/core/generic.py
Outdated
@@ -50,6 +50,7 @@ | |||
from pandas.compat.numpy import function as nv | |||
from pandas.compat import (map, zip, lzip, lrange, string_types, | |||
isidentifier, set_function_name) | |||
from pandas.compat import cPickle as pkl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to the previous line
pandas/core/generic.py
Outdated
@@ -1354,11 +1356,15 @@ def to_pickle(self, path, compression='infer'): | |||
File path | |||
compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' | |||
a string representing the compression to use in the output file | |||
protocol : int | |||
Int which indicates which protocol should be used by the pickler, | |||
default HIGHEST_PROTOCOL (Pickle module). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version added tag (the compression one goes above this), your tag should read 0.21.0
pandas/io/pickle.py
Outdated
@@ -18,6 +18,9 @@ def to_pickle(obj, path, compression='infer'): | |||
File path | |||
compression : {'infer', 'gzip', 'bz2', 'xz', None}, default 'infer' | |||
a string representing the compression to use in the output file | |||
protocol : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
also add a whatsnew in enhancements for 0.21.0 |
I am facing an issue when writing the tests.
Is it because it indirectly calls the wrong |
Try changing to the root of the git repo and running |
@TomAugspurger It solved my problem. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #16252 +/- ##
==========================================
- Coverage 90.33% 90.32% -0.01%
==========================================
Files 164 164
Lines 50890 50891 +1
==========================================
- Hits 45972 45969 -3
- Misses 4918 4922 +4
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16252 +/- ##
==========================================
+ Coverage 90.33% 90.38% +0.04%
==========================================
Files 164 161 -3
Lines 50890 50967 +77
==========================================
+ Hits 45972 46067 +95
+ Misses 4918 4900 -18
Continue to review full report at Codecov.
|
this needs some tests. |
I'm on it. I'll make a new commit, very soon, with the necessary tests. |
@jreback I added some tests for valid and invalid values of the |
@jreback : Do you think that more tests are needed ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -27,6 +27,28 @@ New features | |||
Other Enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
Pickle file I/O protocol parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this section. Can just add a single line with the issue refernce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the 'whatsnew' file accordingly.
small linting failure. |
Oupps! Fixed the linting failure. Should be OK now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. minor comments. ping on green.
pandas/core/generic.py
Outdated
this parameter depend on the version of Python. For Python 2.x, | ||
possible values are 0, 1, 2. For Python>=3.0, 3 is a valid value. | ||
For Python >= 3.4, 4 is a valid value.A negative value for the | ||
protocol parameter is equivalent to setting its value to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a link to the pickle docs where this is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, I added the url.
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -27,7 +27,7 @@ New features | |||
Other Enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
|
|||
- Added protocol parameter to :func:`to_pickle`. The 'protocol' parameter defaults to HIGHEST_PROTOCOL. (:issue:`16252`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:func:to_pickle
has gained a protocol parameter.....
pandas/io/pickle.py
Outdated
Int which indicates which protocol should be used by the pickler, | ||
default HIGHEST_PROTOCOL (Pickle module). The possible values for | ||
this parameter depend on the version of Python. For Python 2.x, | ||
possible values are 0, 1, 2. For Python>=3.0, 3 is a valid value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
With my previous commit, all tests were successful. After modifying docstrings and the whatsnew file, |
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -27,7 +27,8 @@ New features | |||
Other Enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
|
|||
- :func:`to_pickle` has gained a protocol parameter (:issue:`16252`). By default, | |||
this parameter is set to HIGHEST_PROTOCOL (see https://docs.python.org/3/library/pickle.html, 12.1.2). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this render? e.g. we normally use HIGHEST_PROTOCOL <url....>
__
I restarted that CI job. sometimes that tests fails :< minor comment on docs. just ping when pushed. |
@jreback : I pushed the changes. |
thanks! |
keep em coming! |
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'.
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'.
This PR aims at adding an optional
protocol
parameter to the functionto_pickle
.Closes #14488. If needed, I can update the corresponding test (
pandas/tests/io/test_pickle.py
).