Skip to content

Commit 3694e06

Browse files
authored
Add a __dataframe__ method to _VaexDataFrame (#2205)
This will align the implementation with those in other libraries, xref data-apis/dataframe-api#80
1 parent 573d1e1 commit 3694e06

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/vaex-core/vaex/dataframe_protocol.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
For a background and spec, see:
1111
* https://data-apis.org/blog/dataframe_protocol_rfc/
1212
* https://data-apis.org/dataframe-protocol/latest/index.html
13-
13+
1414
Notes
1515
-----
1616
- Interpreting a raw pointer (as in ``Buffer.ptr``) is annoying and unsafe to
@@ -701,6 +701,9 @@ def __init__(self, df: vaex.dataframe.DataFrame, nan_as_null: bool = False, allo
701701
self._nan_as_null = nan_as_null
702702
self._allow_copy = allow_copy
703703

704+
def __dataframe__(self, nan_as_null : bool = False, allow_copy : bool = True) -> "_VaexDataFrame":
705+
return _VaexDataFrame(self._df, nan_as_null=nan_as_null, allow_copy=allow_copy)
706+
704707
@property
705708
def metadata(self) -> Dict[str, Any]:
706709
return {}

tests/dataframe_protocol_test.py

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ def test_VaexDataFrame():
294294
assert df2.select_columns((0, 2))._df[:, 0].tolist() == df2.select_columns_by_name(("x", "z"))._df[:, 0].tolist()
295295
assert df2.select_columns((0, 2))._df[:, 1].tolist() == df2.select_columns_by_name(("x", "z"))._df[:, 1].tolist()
296296

297+
assert_dataframe_equal(df2.__dataframe__(), df)
298+
297299

298300
def test_chunks(df_factory):
299301
x = np.arange(10)

0 commit comments

Comments
 (0)