Skip to content
39 changes: 39 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,42 @@ def closed(self) -> bool:
SequenceT = TypeVar("SequenceT", bound=Sequence[Hashable])

SliceType = Optional[Hashable]


# Arrow PyCapsule Interface
# from https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html#protocol-typehints


class ArrowArrayExportable(Protocol):
"""
An object with an ``__arrow_c_array__`` method.

This method indicates the object is an Arrow-compatible object implementing
the `Arrow PyCapsule Protocol`_ (exposing the `Arrow C Data Interface`_ in
Python), enabling zero-copy Arrow data interchange across libraries.

.. _Arrow PyCapsule Protocol: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
.. _Arrow C Data Interface: https://arrow.apache.org/docs/format/CDataInterface.html

"""

def __arrow_c_array__(
self, requested_schema: object | None = None
) -> tuple[object, object]: ...


class ArrowStreamExportable(Protocol):
"""
An object with an ``__arrow_c_stream__`` method.

This method indicates the object is an Arrow-compatible object implementing
the `Arrow PyCapsule Protocol`_ (exposing the `Arrow C Data Interface`_
for streams in Python), enabling zero-copy Arrow data interchange across
libraries.

.. _Arrow PyCapsule Protocol: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
.. _Arrow C Data Interface: https://arrow.apache.org/docs/format/CDataInterface.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe this should link to the stream interface page instead? https://arrow.apache.org/docs/format/CStreamInterface.html


"""

def __arrow_c_stream__(self, requested_schema: object | None = None) -> object: ...
6 changes: 5 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@
AnyAll,
AnyArrayLike,
ArrayLike,
ArrowArrayExportable,
ArrowStreamExportable,
Axes,
Axis,
AxisInt,
Expand Down Expand Up @@ -1747,7 +1749,9 @@ def __rmatmul__(self, other) -> DataFrame:
# IO methods (to / from other formats)

@classmethod
def from_arrow(cls, data) -> DataFrame:
def from_arrow(
cls, data: ArrowArrayExportable | ArrowStreamExportable
) -> DataFrame:
"""
Construct a DataFrame from a tabular Arrow object.

Expand Down