Skip to content

Commit e5b8edd

Browse files
Update pickle.py to accept URLs
1 parent 2b62da0 commit e5b8edd

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pandas/io/pickle.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
from pandas._typing import FilePathOrBuffer
99

10-
from pandas.io.common import (
11-
_get_handle,
12-
get_filepath_or_buffer as _get_filepath_or_buffer,
13-
)
10+
from pandas.io.common import _get_handle, get_filepath_or_buffer
1411

1512

1613
def to_pickle(
@@ -26,8 +23,9 @@ def to_pickle(
2623
----------
2724
obj : any object
2825
Any python object.
29-
path : str
26+
filepath_or_buffer : str, path object or file-like object
3027
File path, URL, or buffer where the pickled object will be stored.
28+
URL has to be either of S3 or GCS.
3129
compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer'
3230
If 'infer' and 'path_or_url' is path-like, then detect compression from
3331
the following extensions: '.gz', '.bz2', '.zip', or '.xz' (otherwise no
@@ -76,7 +74,7 @@ def to_pickle(
7674
>>> import os
7775
>>> os.remove("./dummy.pkl")
7876
"""
79-
fp_or_buf, _, compression, should_close = _get_filepath_or_buffer(
77+
fp_or_buf, _, compression, should_close = get_filepath_or_buffer(
8078
filepath_or_buffer, compression=compression, mode="wb"
8179
)
8280
if not isinstance(fp_or_buf, str) and compression == "infer":
@@ -110,8 +108,9 @@ def read_pickle(
110108
111109
Parameters
112110
----------
113-
filepath_or_buffer : str
111+
filepath_or_buffer : str, path object or file-like object
114112
File path, URL, or buffer where the pickled object will be loaded from.
113+
URL is not limited to S3 and GCS.
115114
compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer'
116115
If 'infer' and 'path_or_url' is path-like, then detect compression from
117116
the following extensions: '.gz', '.bz2', '.zip', or '.xz' (otherwise no
@@ -158,7 +157,7 @@ def read_pickle(
158157
>>> import os
159158
>>> os.remove("./dummy.pkl")
160159
"""
161-
fp_or_buf, _, compression, should_close = _get_filepath_or_buffer(
160+
fp_or_buf, _, compression, should_close = get_filepath_or_buffer(
162161
filepath_or_buffer, compression=compression
163162
)
164163
if not isinstance(fp_or_buf, str) and compression == "infer":

0 commit comments

Comments
 (0)