Skip to content

Commit 758fa13

Browse files
committed
docs: clarify return values for Arrow C Array export in documentation and type hints
1 parent a3194ba commit 758fa13

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

docs/source/user-guide/io/arrow.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ To import an Arrow table, use :py:func:`datafusion.context.SessionContext.from_a
3535
This will accept any Python object that implements
3636
`__arrow_c_stream__ <https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html#arrowstream-export>`_
3737
or `__arrow_c_array__ <https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html#arrowarray-export>`_
38-
and returns a ``StructArray``. Common pyarrow sources you can use are:
38+
and returns a ``StructArray``.
39+
40+
.. note::
41+
``__arrow_c_array__`` must return ``(array_capsule, schema_capsule)``.
42+
43+
Common pyarrow sources you can use are:
3944

4045
- `Array <https://arrow.apache.org/docs/python/generated/pyarrow.Array.html>`_ (but it must return a Struct Array)
4146
- `Record Batch <https://arrow.apache.org/docs/python/generated/pyarrow.RecordBatch.html>`_

python/datafusion/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ArrowArrayExportable(Protocol):
6464
"""Type hint for object exporting Arrow C Array via Arrow PyCapsule Interface.
6565
6666
https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
67+
68+
The method should return ``(array_capsule, schema_capsule)``.
6769
"""
6870

6971
def __arrow_c_array__( # noqa: D105

python/datafusion/record_batch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def __arrow__(self, *args: object, **kwargs: object) -> pa.RecordBatch:
5757
def __arrow_c_array__(
5858
self, requested_schema: object | None = None
5959
) -> tuple[object, object]:
60-
"""Arrow C Data Interface export."""
60+
"""Arrow C Data Interface export.
61+
62+
Returns:
63+
tuple[object, object]: ``(array_capsule, schema_capsule)``
64+
"""
6165
return self.record_batch.__arrow_c_array__(requested_schema)
6266

6367

src/record_batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl PyRecordBatch {
142142
.downcast_into::<PyCapsule>()
143143
.unwrap();
144144

145-
Ok((schema_capsule, array_capsule))
145+
Ok((array_capsule, schema_capsule))
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)