Skip to content

Commit

Permalink
feat(api): add __dataframe__ implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jun 16, 2023
1 parent 671bc31 commit 804ace3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ibis/backends/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,19 @@ def test_arrow_timestamp_with_time_zone(alltypes):

(batch,) = t.to_pyarrow_batches()
assert batch.schema.types == expected


@pytest.mark.notimpl(["dask", "druid"])
@pytest.mark.notimpl(
["mysql"],
raises=pa.ArrowTypeError,
reason="attempted conversion from decimal to double",
)
@pytest.mark.notimpl(
["impala"], raises=AttributeError, reason="missing `fetchmany` on the cursor"
)
def test_dataframe_protocol(alltypes):
pytest.importorskip("pyarrow", minversion="12")
output = alltypes.__dataframe__()
assert list(output.column_names()) == alltypes.columns
assert alltypes.count().execute() == output.num_rows()
3 changes: 3 additions & 0 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class Table(Expr, _FixedTextJupyterMixin):
def __array__(self, dtype=None):
return self.execute().__array__(dtype)

def __dataframe__(self):
return self.to_pyarrow().__dataframe__()

def as_table(self) -> Table:
"""Promote the expression to a table.
Expand Down

0 comments on commit 804ace3

Please sign in to comment.