-
-
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
Closed
Closed
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
66a35e8
Added 'protocol' parameter to 'to_pickle'.
jbschiratti 04bc5c2
Added 'versionadded' tag, improved docstring + fixed import.
jbschiratti 4bf0386
Added docstring for negative protocol parameter.
jbschiratti 35f8d18
Added tests for new 'protocol' parameter in 'to_pickle'.
jbschiratti 9c9d38f
Added enhancement to 'whatsnew' file.
jbschiratti 352220b
Fix : Fixed error message in 'test_read_bad_versions'.
jbschiratti 460ca0c
Shortened paragraph addded in 'whatsnew'.
jbschiratti 7631146
Fix : added issue number.
jbschiratti 14bc485
Fix : removed unused import.
jbschiratti 20a854d
Added ref for protocol parameter + edited whatsnew.
jbschiratti 8eb660d
Minor change on whatsnew.
jbschiratti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
from pandas.io.common import _get_handle, _infer_compression | ||
|
||
|
||
def to_pickle(obj, path, compression='infer'): | ||
def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): | ||
""" | ||
Pickle (serialize) object to input file path | ||
|
||
|
@@ -20,13 +20,28 @@ def to_pickle(obj, path, compression='infer'): | |
a string representing the compression to use in the output file | ||
|
||
.. versionadded:: 0.20.0 | ||
protocol : int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
Int which indicates which protocol should be used by the pickler, | ||
default HIGHEST_PROTOCOL (see [1], paragraph 12.1.2). 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. | ||
For Python >= 3.4, 4 is a valid value. A negative value for the | ||
protocol parameter is equivalent to setting its value to | ||
HIGHEST_PROTOCOL. | ||
|
||
.. [1] https://docs.python.org/3/library/pickle.html | ||
.. versionadded:: 0.21.0 | ||
|
||
|
||
""" | ||
inferred_compression = _infer_compression(path, compression) | ||
f, fh = _get_handle(path, 'wb', | ||
compression=inferred_compression, | ||
is_text=False) | ||
if protocol < 0: | ||
protocol = pkl.HIGHEST_PROTOCOL | ||
try: | ||
pkl.dump(obj, f, protocol=pkl.HIGHEST_PROTOCOL) | ||
pkl.dump(obj, f, protocol=protocol) | ||
finally: | ||
for _f in fh: | ||
_f.close() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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....>
__