Skip to content

Commit 06c8584

Browse files
shadiakiki1986proost
authored andcommitted
DOC: add example of pyarrow usage favored over the deprecated to_msgpack (pandas-dev#28494)
1 parent 3dc7ab6 commit 06c8584

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pandas/core/generic.py

+11
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,17 @@ def to_msgpack(self, path_or_buf=None, encoding="utf-8", **kwargs):
25242524
It is recommended to use pyarrow for on-the-wire transmission of
25252525
pandas objects.
25262526
2527+
Example pyarrow usage:
2528+
2529+
>>> import pandas as pd
2530+
>>> import pyarrow as pa
2531+
>>> df = pd.DataFrame({'A': [1, 2, 3]})
2532+
>>> context = pa.default_serialization_context()
2533+
>>> df_bytestring = context.serialize(df).to_buffer().to_pybytes()
2534+
2535+
For documentation on pyarrow, see `here
2536+
<https://arrow.apache.org/docs/python/index.html>`__.
2537+
25272538
Parameters
25282539
----------
25292540
path : str, buffer-like, or None

pandas/io/packers.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ def to_msgpack(path_or_buf, *args, **kwargs):
105105
It is recommended to use pyarrow for on-the-wire transmission of
106106
pandas objects.
107107
108+
Example pyarrow usage:
109+
110+
>>> import pandas as pd
111+
>>> import pyarrow as pa
112+
>>> df = pd.DataFrame({'A': [1, 2, 3]})
113+
>>> context = pa.default_serialization_context()
114+
>>> df_bytestring = context.serialize(df).to_buffer().to_pybytes()
115+
116+
For documentation on pyarrow, see `here
117+
<https://arrow.apache.org/docs/python/index.html>`__.
118+
108119
Parameters
109120
----------
110121
path_or_buf : string File path, buffer-like, or None
@@ -120,7 +131,9 @@ def to_msgpack(path_or_buf, *args, **kwargs):
120131
"to_msgpack is deprecated and will be removed in a "
121132
"future version.\n"
122133
"It is recommended to use pyarrow for on-the-wire "
123-
"transmission of pandas objects.",
134+
"transmission of pandas objects.\n"
135+
"For a full example, check\n"
136+
"https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_msgpack.html", # noqa: E501
124137
FutureWarning,
125138
stacklevel=3,
126139
)

0 commit comments

Comments
 (0)