Skip to content

Commit 0be24e0

Browse files
authored
REF: Store dataframe protocol column buffers in attrs (#47217)
1 parent 7c68ecc commit 0be24e0

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

pandas/core/exchange/from_dataframe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def protocol_df_chunk_to_pandas(df: DataFrameXchg) -> pd.DataFrame:
136136
buffers.append(buf)
137137

138138
pandas_df = pd.DataFrame(columns)
139-
pandas_df._buffers = buffers
139+
pandas_df.attrs["_EXCHANGE_PROTOCOL_BUFFERS"] = buffers
140140
return pandas_df
141141

142142

pandas/tests/exchange/__init__.py

Whitespace-only changes.

pandas/tests/exchange/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pandas as pd
44

55

6-
@pytest.fixture(scope="package")
6+
@pytest.fixture
77
def df_from_dict():
88
def maker(dct, is_categorical=False):
99
df = pd.DataFrame(dct)

pandas/tests/exchange/test_impl.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ def test_dataframe(data):
8484
indices = (0, 2)
8585
names = tuple(list(data.keys())[idx] for idx in indices)
8686

87-
tm.assert_frame_equal(
88-
from_dataframe(df2.select_columns(indices)),
89-
from_dataframe(df2.select_columns_by_name(names)),
90-
)
87+
result = from_dataframe(df2.select_columns(indices))
88+
expected = from_dataframe(df2.select_columns_by_name(names))
89+
tm.assert_frame_equal(result, expected)
90+
91+
assert isinstance(result.attrs["_EXCHANGE_PROTOCOL_BUFFERS"], list)
92+
assert isinstance(expected.attrs["_EXCHANGE_PROTOCOL_BUFFERS"], list)
9193

9294

9395
def test_missing_from_masked():

0 commit comments

Comments
 (0)