Skip to content
Open
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
33 changes: 7 additions & 26 deletions docs/source/python/interchange_protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ libraries in the Python ecosystem. See more about the
standard in the
`protocol documentation <https://data-apis.org/dataframe-protocol/latest/index.html>`_.

.. note::

The recommended way to convert between dataframe libraries is through
the :ref:`arrow-pycapsule-interface`, for example by calling ``pa.table(df)``
on a dataframe object that implements it.

From PyArrow to other libraries: ``__dataframe__()`` method
-----------------------------------------------------------

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

We can for example take a pandas dataframe and construct a
We can for example take a polars dataframe and construct a
PyArrow table with the use of the interchange protocol:

.. code-block:: python

>>> import pyarrow
>>> from pyarrow.interchange import from_dataframe

>>> import pandas as pd
>>> df = pd.DataFrame({
... "n_attendees": [100, 10, 1],
... "country": ["Italy", "Spain", "Slovenia"],
... })
>>> df
n_attendees country
0 100 Italy
1 10 Spain
2 1 Slovenia
>>> from_dataframe(df)
pyarrow.Table
n_attendees: int64
country: large_string
----
n_attendees: [[100,10,1]]
country: [["Italy","Spain","Slovenia"]]

We can do the same with a polars dataframe:

.. code-block:: python

>>> import polars as pl # doctest: +SKIP
Expand Down
25 changes: 0 additions & 25 deletions python/pyarrow/interchange/from_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,6 @@ def from_dataframe(df: DataFrameObject, allow_copy=True) -> pa.Table:
Returns
-------
pa.Table

Examples
--------
>>> import pyarrow
>>> from pyarrow.interchange import from_dataframe

Convert a pandas dataframe to a pyarrow table:

>>> import pandas as pd
>>> df = pd.DataFrame({
... "n_attendees": [100, 10, 1],
... "country": ["Italy", "Spain", "Slovenia"],
... })
>>> df
n_attendees country
0 100 Italy
1 10 Spain
2 1 Slovenia
>>> from_dataframe(df)
pyarrow.Table
n_attendees: int64
country: large_string
----
n_attendees: [[100,10,1]]
country: [["Italy","Spain","Slovenia"]]
"""
if isinstance(df, pa.Table):
return df
Expand Down
4 changes: 4 additions & 0 deletions python/pyarrow/tests/interchange/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
pass


pytestmark = pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated.")


@pytest.mark.parametrize("unit", ['s', 'ms', 'us', 'ns'])
@pytest.mark.parametrize("tz", ['', 'America/New_York', '+07:30', '-04:30'])
def test_datetime(unit, tz):
Expand Down
Loading