Skip to content

Commit 09f9893

Browse files
committed
docstring validation, fixup tests
1 parent 31e174f commit 09f9893

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

pandas/core/frame.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,14 @@ def __dataframe__(
916916
"""
917917
Return the dataframe interchange object implementing the interchange protocol.
918918
919+
.. deprecated:: 3.0.0
920+
921+
The Dataframe Interchange Protocol is deprecated.
922+
For dataframe-agnostic code, you may want to look into:
923+
924+
- `Arrow PyCapsule Interface <https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html>`_
925+
- `Narwhals <https://github.com/narwhals-dev/narwhals>`_
926+
919927
.. note::
920928
921929
For new development, we highly recommend using the Arrow C Data Interface
@@ -929,14 +937,6 @@ def __dataframe__(
929937
- converting to pandas: for pandas >= 2.0.3
930938
- converting from pandas: for pandas >= 3.0.0
931939
932-
.. deprecated:: 3.0.0
933-
934-
The Dataframe Interchange Protocol is deprecated.
935-
For dataframe-agnostic code, you may want to look into:
936-
937-
- `Arrow PyCapsule Interface <https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html>`_
938-
- `Narwhals <https://github.com/narwhals-dev/narwhals>`_
939-
940940
Parameters
941941
----------
942942
nan_as_null : bool, default False

pandas/tests/interchange/test_impl.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def test_large_string_pyarrow():
9494
tm.assert_frame_equal(result, expected)
9595

9696
# check round-trip
97-
assert pa.Table.equals(pa.interchange.from_dataframe(result), table)
97+
# Don't check stacklevel as PyArrow calls the deprecated `__dataframe__` method.
98+
with tm.assert_produces_warning(match="Interchange", check_stacklevel=False):
99+
assert pa.Table.equals(pa.interchange.from_dataframe(result), table)
98100

99101

100102
@pytest.mark.parametrize(
@@ -121,6 +123,7 @@ def test_bitmasks_pyarrow(offset, length, expected_values):
121123
tm.assert_frame_equal(result, expected)
122124

123125
# check round-trip
126+
# Don't check stacklevel as PyArrow calls the deprecated `__dataframe__` method.
124127
with tm.assert_produces_warning(match="Interchange", check_stacklevel=False):
125128
assert pa.Table.equals(pa.interchange.from_dataframe(result), table)
126129

@@ -297,7 +300,9 @@ def test_empty_pyarrow(data):
297300
from pyarrow.interchange import from_dataframe as pa_from_dataframe
298301

299302
expected = pd.DataFrame(data)
300-
arrow_df = pa_from_dataframe(expected)
303+
# Don't check stacklevel as PyArrow calls the deprecated `__dataframe__` method.
304+
with tm.assert_produces_warning(match="Interchange", check_stacklevel=False):
305+
arrow_df = pa_from_dataframe(expected)
301306
result = from_dataframe(arrow_df)
302307
tm.assert_frame_equal(result, expected, check_column_type=False)
303308

@@ -441,7 +446,8 @@ def test_large_string():
441446
# GH#56702
442447
pytest.importorskip("pyarrow")
443448
df = pd.DataFrame({"a": ["x"]}, dtype="large_string[pyarrow]")
444-
with tm.assert_produces_warning(match="Interchange"):
449+
# Don't check stacklevel as PyArrow calls the deprecated `__dataframe__` method.
450+
with tm.assert_produces_warning(match="Interchange", check_stacklevel=False):
445451
result = pd.api.interchange.from_dataframe(df.__dataframe__())
446452
expected = pd.DataFrame({"a": ["x"]}, dtype="str")
447453
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)