Skip to content

Commit 54c2f59

Browse files
committed
feat: add Arrow interoperability support to RecordBatch classes
1 parent 77995f7 commit 54c2f59

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

python/datafusion/record_batch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def to_pyarrow(self) -> pa.RecordBatch:
4646
"""Convert to :py:class:`pa.RecordBatch`."""
4747
return self.record_batch.to_pyarrow()
4848

49+
def __arrow__(self, *args: object, **kwargs: object) -> pa.RecordBatch:
50+
"""Return a :py:class:`pa.RecordBatch` for Arrow interoperability.
51+
52+
This enables ``datafusion.record_batch.RecordBatch`` instances to be
53+
automatically recognized by PyArrow when passed to its APIs.
54+
"""
55+
return self.to_pyarrow()
56+
4957
def __arrow_c_array__(
5058
self, requested_schema: object | None = None
5159
) -> tuple[object, object]:

src/record_batch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ impl PyRecordBatch {
7979
self.batch.to_pyarrow(py)
8080
}
8181

82+
fn __arrow__(&self, py: Python) -> PyResult<PyObject> {
83+
self.to_pyarrow(py)
84+
}
85+
8286
#[pyo3(signature = (requested_schema=None))]
8387
fn __arrow_c_array__<'py>(
8488
&self,

0 commit comments

Comments
 (0)