From 25d830e1ab927845c9f3de7993863a9ffb420511 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 21 Dec 2023 17:59:31 +0100 Subject: [PATCH] Add methods for the Arrow PyCapsule Protocol to DataFrame/Column interchange protocol objects --- protocol/dataframe_protocol.py | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/protocol/dataframe_protocol.py b/protocol/dataframe_protocol.py index e918e1e4..ec2be983 100644 --- a/protocol/dataframe_protocol.py +++ b/protocol/dataframe_protocol.py @@ -350,6 +350,41 @@ def get_buffers(self) -> ColumnBuffers: """ pass + def __arrow_c_schema__(self) -> object: + """ + Export the data type of the Column to a Arrow C schema PyCapsule. + + Returns + ------- + PyCapsule + """ + pass + + def __arrow_c_array__( + self, requested_schema: Optional[object] = None + ) -> Tuple[object, object]: + """ + Export the Column as an Arrow C array and schema PyCapsule. + + If the Column consists of multiple chunks, this method should raise + an error. + + Parameters + ---------- + requested_schema : PyCapsule, default None + The schema to which the dataframe should be casted, passed as a + PyCapsule containing a C ArrowSchema representation of the + requested schema. + If None, the array will be returned as-is, with a type matching the + one returned by ``__arrow_c_schema__()``. + + Returns + ------- + Tuple[PyCapsule, PyCapsule] + A pair of PyCapsules containing a C ArrowSchema and ArrowArray, + respectively. + """ + pass # def get_children(self) -> Iterable[Column]: # """ @@ -490,3 +525,32 @@ def get_chunks(self, n_chunks: Optional[int] = None) -> Iterable["DataFrame"]: same way. """ pass + + def __arrow_c_schema__(self) -> object: + """ + Export the schema of the DataFrae to a Arrow C schema PyCapsule. + + Returns + ------- + PyCapsule + """ + pass + + def __arrow_c_stream__(self, requested_schema: Optional[object] = None) -> object: + """ + Export the DataFrame as an Arrow C stream PyCapsule. + + Parameters + ---------- + requested_schema : PyCapsule, default None + The schema to which the dataframe should be casted, passed as a + PyCapsule containing a C ArrowSchema representation of the + requested schema. + If None, the array will be returned as-is, with a type matching the + one returned by ``__arrow_c_schema__()``. + + Returns + ------- + PyCapsule + """ + pass