Skip to content

Commit 13b8f4a

Browse files
DOC: add example of pyarrow usage favored over the deprecated to_msgpack
1 parent 367670e commit 13b8f4a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ I/O
206206
- Improve infinity parsing. :meth:`read_csv` now interprets ``Infinity``, ``+Infinity``, ``-Infinity`` as floating point values (:issue:`10065`)
207207
- Bug in :meth:`DataFrame.to_csv` where values were truncated when the length of ``na_rep`` was shorter than the text input data. (:issue:`25099`)
208208
- Bug in :func:`DataFrame.to_string` where values were truncated using display options instead of outputting the full content (:issue:`9784`)
209+
- Docs for the deprecated :func:`DataFrame.to_msgpack` give an example usage of the recommended pyarrow
209210

210211
Plotting
211212
^^^^^^^^

pandas/core/generic.py

Lines changed: 11 additions & 0 deletions
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

Lines changed: 14 additions & 1 deletion
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)