diff --git a/docs/source/python/interchange_protocol.rst b/docs/source/python/interchange_protocol.rst index efb10d2ab52e..a586a364ffcd 100644 --- a/docs/source/python/interchange_protocol.rst +++ b/docs/source/python/interchange_protocol.rst @@ -36,6 +36,12 @@ libraries in the Python ecosystem. See more about the standard in the `protocol documentation `_. +.. 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 ----------------------------------------------------------- @@ -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 diff --git a/python/pyarrow/interchange/from_dataframe.py b/python/pyarrow/interchange/from_dataframe.py index fcaec41e3dcd..fc6530a83316 100644 --- a/python/pyarrow/interchange/from_dataframe.py +++ b/python/pyarrow/interchange/from_dataframe.py @@ -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 diff --git a/python/pyarrow/tests/interchange/test_conversion.py b/python/pyarrow/tests/interchange/test_conversion.py index 50da6693afff..81713b94e6db 100644 --- a/python/pyarrow/tests/interchange/test_conversion.py +++ b/python/pyarrow/tests/interchange/test_conversion.py @@ -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):