Skip to content

DOC: add example of pyarrow usage favored over the deprecated to_msgpack #28494

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,17 @@ def to_msgpack(self, path_or_buf=None, encoding="utf-8", **kwargs):
It is recommended to use pyarrow for on-the-wire transmission of
pandas objects.

Example pyarrow usage:

>>> import pandas as pd
>>> import pyarrow as pa
>>> df = pd.DataFrame({'A': [1, 2, 3]})
>>> context = pa.default_serialization_context()
>>> df_bytestring = context.serialize(df).to_buffer().to_pybytes()

For documentation on pyarrow, see `here
<https://arrow.apache.org/docs/python/index.html>`__.

Parameters
----------
path : str, buffer-like, or None
Expand Down
15 changes: 14 additions & 1 deletion pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ def to_msgpack(path_or_buf, *args, **kwargs):
It is recommended to use pyarrow for on-the-wire transmission of
pandas objects.

Example pyarrow usage:

>>> import pandas as pd
>>> import pyarrow as pa
>>> df = pd.DataFrame({'A': [1, 2, 3]})
>>> context = pa.default_serialization_context()
>>> df_bytestring = context.serialize(df).to_buffer().to_pybytes()

For documentation on pyarrow, see `here
<https://arrow.apache.org/docs/python/index.html>`__.

Parameters
----------
path_or_buf : string File path, buffer-like, or None
Expand All @@ -120,7 +131,9 @@ def to_msgpack(path_or_buf, *args, **kwargs):
"to_msgpack is deprecated and will be removed in a "
"future version.\n"
"It is recommended to use pyarrow for on-the-wire "
"transmission of pandas objects.",
"transmission of pandas objects.\n"
"For a full example, check\n"
"https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_msgpack.html", # noqa: E501
FutureWarning,
stacklevel=3,
)
Expand Down