Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add __dataframe__ implementation #6464

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.ArrowInvalid,
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