kylebarron commented on code in PR #5355:
URL: https://github.com/apache/arrow-rs/pull/5355#discussion_r1473114374


##########
arrow/src/pyarrow.rs:
##########
@@ -355,7 +355,12 @@ impl FromPyArrow for RecordBatch {
                 ));
             }
             let array = StructArray::from(array_data);
-            return Ok(array.into());
+            // StructArray does not embed metadata from schema. We need to 
override
+            // the output schema with the schema from the capsule.
+            let schema = 
Arc::new(Schema::try_from(schema_ptr).map_err(to_py_err)?);
+            return RecordBatch::from(array)
+                .with_schema(schema)
+                .map_err(to_py_err);

Review Comment:
   Instead of first inferring a schema from the record batch and then 
overwriting it, maybe it would be clearer to [access the 
columns](https://docs.rs/arrow-array/50.0.0/src/arrow_array/record_batch.rs.html#513)
 and then use `RecordBatch::try_new`?
   ```rs
   let schema = Arc::new(Schema::try_from(schema_ptr).map_err(to_py_err)?);
   let (_fields, columns, nulls) = array.into_parts();
   // Assert null count is 0
   return RecordBatch::try_new(schema, columns).map_err(to_py_err);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to