From c9ff617ca1f74f07c8dbf9852780ae7bac54031c Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Mon, 22 Jul 2024 15:02:20 -0500 Subject: [PATCH] feat(pyarrow): support `__arrow_c_schema__` on `ibis.Schema` objects --- ibis/expr/schema.py | 3 +++ ibis/expr/tests/test_schema.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/ibis/expr/schema.py b/ibis/expr/schema.py index 6f3553dd28f5..8db79fa41c36 100644 --- a/ibis/expr/schema.py +++ b/ibis/expr/schema.py @@ -183,6 +183,9 @@ def to_pyarrow(self): return PyArrowSchema.from_ibis(self) + def __arrow_c_schema__(self): + return self.to_pyarrow().__arrow_c_schema__() + def to_polars(self): """Return the equivalent polars schema.""" from ibis.formats.polars import PolarsSchema diff --git a/ibis/expr/tests/test_schema.py b/ibis/expr/tests/test_schema.py index 198eeae4c855..35fd96e4c007 100644 --- a/ibis/expr/tests/test_schema.py +++ b/ibis/expr/tests/test_schema.py @@ -393,6 +393,13 @@ def test_schema_from_to_pyarrow_schema(): assert restored_schema == pyarrow_schema +def test_schema___arrow_c_schema__(): + pytest.importorskip("pyarrow") + schema = sch.Schema({"a": dt.int64, "b": dt.string, "c": dt.boolean}) + # smoketest, since no way to create schema from capsule in current pyarrow + assert schema.__arrow_c_schema__() is not None + + @pytest.mark.parametrize("lazy", [False, True]) def test_schema_infer_polars_dataframe(lazy): pl = pytest.importorskip("polars")