judahrand commented on code in PR #38520:
URL: https://github.com/apache/arrow/pull/38520#discussion_r1422716152
##########
python/pyarrow/table.pxi:
##########
@@ -3986,6 +3986,59 @@ cdef class Table(_Tabular):
result.validate()
return result
+ @staticmethod
+ def from_struct_array(struct_array):
+ """
+ Construct a Table from a StructArray.
+
+ Each field in the StructArray will become a column in the resulting
+ ``Table``.
+
+ Parameters
+ ----------
+ struct_array : StructArray or ChunkedArray
+ Array to construct the table from.
+
+ Returns
+ -------
+ pyarrow.Table
+
+ Examples
+ --------
+ >>> import pyarrow as pa
+ >>> struct = pa.array([{'n_legs': 2, 'animals': 'Parrot'},
+ ... {'year': 2022, 'n_legs': 4}])
+ >>> pa.Table.from_struct_array(struct).to_pandas()
+ animals n_legs year
+ 0 Parrot 2 NaN
+ 1 None 4 2022.0
+ """
+ if isinstance(struct_array, Array):
+ struct_array = chunked_array([struct_array])
+ return Table.from_batches([
+ RecordBatch.from_struct_array(chunk)
+ for chunk in struct_array.chunks
+ ])
Review Comment:
https://github.com/apache/arrow/pull/38520/commits/52a792a6d6b371322c3bc860301ecb21467afbe0
--
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]