Skip to content

Commit 2c524f1

Browse files
EnricoMialamb
andauthored
Align buffers from Python (FFI) (#6472)
* Align buffers in RecordBatch.from_pyarrow_bound * Update arrow/src/pyarrow.rs * cargo fmt --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 4389cf9 commit 2c524f1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arrow/src/pyarrow.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,19 @@ impl FromPyArrow for RecordBatch {
363363

364364
let schema_ptr = unsafe { schema_capsule.reference::<FFI_ArrowSchema>() };
365365
let ffi_array = unsafe { FFI_ArrowArray::from_raw(array_capsule.pointer().cast()) };
366-
let array_data = unsafe { ffi::from_ffi(ffi_array, schema_ptr) }.map_err(to_py_err)?;
366+
let mut array_data =
367+
unsafe { ffi::from_ffi(ffi_array, schema_ptr) }.map_err(to_py_err)?;
367368
if !matches!(array_data.data_type(), DataType::Struct(_)) {
368369
return Err(PyTypeError::new_err(
369370
"Expected Struct type from __arrow_c_array.",
370371
));
371372
}
372373
let options = RecordBatchOptions::default().with_row_count(Some(array_data.len()));
374+
// Ensure data is aligned (by potentially copying the buffers).
375+
// This is needed because some python code (for example the
376+
// python flight client) produces unaligned buffers
377+
// See https://github.com/apache/arrow/issues/43552 for details
378+
array_data.align_buffers();
373379
let array = StructArray::from(array_data);
374380
// StructArray does not embed metadata from schema. We need to override
375381
// the output schema with the schema from the capsule.

0 commit comments

Comments
 (0)