Skip to content

Commit bdcb076

Browse files
committed
Refactor pyarrow.RecordBatch fetching to a separate function for reuse
1 parent e3d6791 commit bdcb076

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/dataframe.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ fn record_batches_to_pyarrow(
407407
.collect()
408408
}
409409

410+
/// Fetch the `pyarrow.RecordBatch` class
411+
fn pyarrow_record_batch_class(py: Python<'_>) -> PyResult<Bound<'_, PyAny>> {
412+
py.import("pyarrow")?.getattr("RecordBatch")
413+
}
414+
410415
#[pymethods]
411416
impl PyDataFrame {
412417
/// Enable selection for `df[col]`, `df[col1, col2, col3]`, and `df[[col1, col2, col3]]`
@@ -579,7 +584,7 @@ impl PyDataFrame {
579584
.map_err(PyDataFusionError::from)?;
580585

581586
// Fetch pyarrow.RecordBatch class once per call and reuse it
582-
let record_batch_class = py.import("pyarrow")?.getattr("RecordBatch")?;
587+
let record_batch_class = pyarrow_record_batch_class(py)?;
583588

584589
record_batches_to_pyarrow(py, &record_batch_class, batches)
585590
}
@@ -597,7 +602,7 @@ impl PyDataFrame {
597602
.map_err(PyDataFusionError::from)?;
598603

599604
// Fetch pyarrow.RecordBatch class once and reuse it for all partitions
600-
let record_batch_class = py.import("pyarrow")?.getattr("RecordBatch")?;
605+
let record_batch_class = pyarrow_record_batch_class(py)?;
601606

602607
batches
603608
.into_iter()

0 commit comments

Comments
 (0)