Skip to content

Commit fe298b4

Browse files
authored
GH-49628: [Python][Interchange protocol] Suppress warnings for pandas 4.0.0 and update docs (#49630)
### Rationale for this change Pandas is moving the dataframe interchange protocol out of the repo in the next major release (4.0.0). ### What changes are included in this PR? Filterwarnings are added and the pandas example is removed from the interchange documentation. ### Are these changes tested? Yes, via CI. ### Are there any user-facing changes? No. * GitHub Issue: #49628 Authored-by: AlenkaF <frim.alenka@gmail.com> Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
1 parent 1f94910 commit fe298b4

File tree

3 files changed

+11
-51
lines changed

3 files changed

+11
-51
lines changed

docs/source/python/interchange_protocol.rst

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ libraries in the Python ecosystem. See more about the
3636
standard in the
3737
`protocol documentation <https://data-apis.org/dataframe-protocol/latest/index.html>`_.
3838

39+
.. note::
40+
41+
The recommended way to convert between dataframe libraries is through
42+
the :ref:`arrow-pycapsule-interface`, for example by calling ``pa.table(df)``
43+
on a dataframe object that implements it.
44+
3945
From PyArrow to other libraries: ``__dataframe__()`` method
4046
-----------------------------------------------------------
4147

@@ -61,34 +67,9 @@ from any dataframe object that implements the
6167
``__dataframe__()`` method via the dataframe interchange
6268
protocol.
6369

64-
We can for example take a pandas dataframe and construct a
70+
We can for example take a polars dataframe and construct a
6571
PyArrow table with the use of the interchange protocol:
6672

67-
.. code-block:: python
68-
69-
>>> import pyarrow
70-
>>> from pyarrow.interchange import from_dataframe
71-
72-
>>> import pandas as pd
73-
>>> df = pd.DataFrame({
74-
... "n_attendees": [100, 10, 1],
75-
... "country": ["Italy", "Spain", "Slovenia"],
76-
... })
77-
>>> df
78-
n_attendees country
79-
0 100 Italy
80-
1 10 Spain
81-
2 1 Slovenia
82-
>>> from_dataframe(df)
83-
pyarrow.Table
84-
n_attendees: int64
85-
country: large_string
86-
----
87-
n_attendees: [[100,10,1]]
88-
country: [["Italy","Spain","Slovenia"]]
89-
90-
We can do the same with a polars dataframe:
91-
9273
.. code-block:: python
9374
9475
>>> import polars as pl # doctest: +SKIP

python/pyarrow/interchange/from_dataframe.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,6 @@ def from_dataframe(df: DataFrameObject, allow_copy=True) -> pa.Table:
7676
Returns
7777
-------
7878
pa.Table
79-
80-
Examples
81-
--------
82-
>>> import pyarrow
83-
>>> from pyarrow.interchange import from_dataframe
84-
85-
Convert a pandas dataframe to a pyarrow table:
86-
87-
>>> import pandas as pd
88-
>>> df = pd.DataFrame({
89-
... "n_attendees": [100, 10, 1],
90-
... "country": ["Italy", "Spain", "Slovenia"],
91-
... })
92-
>>> df
93-
n_attendees country
94-
0 100 Italy
95-
1 10 Spain
96-
2 1 Slovenia
97-
>>> from_dataframe(df)
98-
pyarrow.Table
99-
n_attendees: int64
100-
country: large_string
101-
----
102-
n_attendees: [[100,10,1]]
103-
country: [["Italy","Spain","Slovenia"]]
10479
"""
10580
if isinstance(df, pa.Table):
10681
return df

python/pyarrow/tests/interchange/test_conversion.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
pass
4141

4242

43+
pytestmark = pytest.mark.filterwarnings(
44+
"ignore:The Dataframe Interchange Protocol is deprecated.")
45+
46+
4347
@pytest.mark.parametrize("unit", ['s', 'ms', 'us', 'ns'])
4448
@pytest.mark.parametrize("tz", ['', 'America/New_York', '+07:30', '-04:30'])
4549
def test_datetime(unit, tz):

0 commit comments

Comments
 (0)