Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 1 addition & 26 deletions docs/source/python/interchange_protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,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
Comment thread
AlenkaF marked this conversation as resolved.
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
30 changes: 30 additions & 0 deletions python/pyarrow/tests/interchange/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def test_offset_of_sliced_array():
# check_index=False, check_names=False)


@pytest.mark.filterwarnings(
Comment thread
AlenkaF marked this conversation as resolved.
Outdated
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
@pytest.mark.parametrize(
"uint", [pa.uint8(), pa.uint16(), pa.uint32()]
Expand Down Expand Up @@ -146,6 +149,9 @@ def test_pandas_roundtrip(uint, int, float, np_float_str):
assert table_protocol.column_names() == result_protocol.column_names()


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_pandas_roundtrip_string():
# See https://github.com/pandas-dev/pandas/issues/50554
Expand Down Expand Up @@ -175,6 +181,9 @@ def test_pandas_roundtrip_string():
assert table_protocol.column_names() == result_protocol.column_names()


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_pandas_roundtrip_large_string():
# See https://github.com/pandas-dev/pandas/issues/50554
Expand Down Expand Up @@ -212,6 +221,9 @@ def test_pandas_roundtrip_large_string():
pandas_from_dataframe(table)


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_pandas_roundtrip_string_with_missing():
# See https://github.com/pandas-dev/pandas/issues/50554
Expand Down Expand Up @@ -244,6 +256,9 @@ def test_pandas_roundtrip_string_with_missing():
pandas_from_dataframe(table)


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_pandas_roundtrip_categorical():
if Version(pd.__version__) < Version("2.0.2"):
Expand Down Expand Up @@ -292,6 +307,9 @@ def test_pandas_roundtrip_categorical():
assert isinstance(desc_cat_result["categories"]._col, pa.Array)


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
@pytest.mark.parametrize("unit", ['s', 'ms', 'us', 'ns'])
def test_pandas_roundtrip_datetime(unit):
Expand Down Expand Up @@ -328,6 +346,9 @@ def test_pandas_roundtrip_datetime(unit):
assert expected_protocol.column_names() == result_protocol.column_names()


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
@pytest.mark.parametrize(
"np_float_str", ["float32", "float64"]
Expand All @@ -353,6 +374,9 @@ def test_pandas_to_pyarrow_with_missing(np_float_str):
assert result.equals(expected)


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_pandas_to_pyarrow_float16_with_missing():
if Version(pd.__version__) < Version("1.5.0"):
Expand Down Expand Up @@ -476,6 +500,9 @@ def test_nan_as_null():
table.__dataframe__(nan_as_null=True)


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_allow_copy_false():
if Version(pd.__version__) < Version("1.5.0"):
Expand All @@ -495,6 +522,9 @@ def test_allow_copy_false():
pi.from_dataframe(df, allow_copy=False)


@pytest.mark.filterwarnings(
"ignore:The Dataframe Interchange Protocol is deprecated."
)
@pytest.mark.pandas
def test_allow_copy_false_bool_categorical():
if Version(pd.__version__) < Version("1.5.0"):
Expand Down
Loading