Skip to content

Commit 01e0607

Browse files
committed
Add a __dataframe__ method to the protocol dataframe object
This will align the implementation with those in other libraries, xref data-apis/dataframe-api#80.
1 parent 7b0d597 commit 01e0607

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

python/cudf/cudf/core/df_protocol.py

+10
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@ def __init__(
529529
self._nan_as_null = nan_as_null
530530
self._allow_copy = allow_copy
531531

532+
def __dataframe__(
533+
self, nan_as_null: bool = False, allow_copy: bool = True
534+
) -> "_CuDFDataFrame":
535+
"""
536+
See the docstring of the `cudf.DataFrame.__dataframe__` for details
537+
"""
538+
return _CuDFDataFrame(
539+
self._df, nan_as_null=nan_as_null, allow_copy=allow_copy
540+
)
541+
532542
@property
533543
def metadata(self):
534544
# `index` isn't a regular column, and the protocol doesn't support row

python/cudf/cudf/tests/test_df_protocol.py

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def test_from_dataframe():
124124
df2 = cudf.from_dataframe(df1)
125125
assert_eq(df1, df2)
126126

127+
df3 = cudf.from_dataframe(df2)
128+
assert_eq(df1, df3)
129+
127130

128131
def test_int_dtype():
129132
data_int = dict(a=[1, 2, 3], b=[9, 10, 11])

0 commit comments

Comments
 (0)