Skip to content

Commit

Permalink
Add a __dataframe__ method to the protocol dataframe object
Browse files Browse the repository at this point in the history
This will align the implementation with those in other libraries,
xref data-apis/dataframe-api#80.
  • Loading branch information
rgommers committed Sep 13, 2022
1 parent 7b0d597 commit 01e0607
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/cudf/cudf/core/df_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,16 @@ def __init__(
self._nan_as_null = nan_as_null
self._allow_copy = allow_copy

def __dataframe__(
self, nan_as_null: bool = False, allow_copy: bool = True
) -> "_CuDFDataFrame":
"""
See the docstring of the `cudf.DataFrame.__dataframe__` for details
"""
return _CuDFDataFrame(
self._df, nan_as_null=nan_as_null, allow_copy=allow_copy
)

@property
def metadata(self):
# `index` isn't a regular column, and the protocol doesn't support row
Expand Down
3 changes: 3 additions & 0 deletions python/cudf/cudf/tests/test_df_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def test_from_dataframe():
df2 = cudf.from_dataframe(df1)
assert_eq(df1, df2)

df3 = cudf.from_dataframe(df2)
assert_eq(df1, df3)


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

0 comments on commit 01e0607

Please sign in to comment.