kou commented on code in PR #38520:
URL: https://github.com/apache/arrow/pull/38520#discussion_r1423120960


##########
python/pyarrow/tests/test_table.py:
##########
@@ -878,6 +878,85 @@ def test_recordbatch_from_struct_array():
     ))
 
 
+def test_recordbatch_to_struct_array():
+    batch = pa.RecordBatch.from_arrays(
+        [
+            pa.array([1, None], type=pa.int32()),
+            pa.array([None, 1.0], type=pa.float32()),
+        ], ["ints", "floats"]
+    )
+    result = batch.to_struct_array()
+    assert result.equals(pa.array(
+        [{"ints": 1}, {"floats": 1.0}],
+        type=pa.struct([("ints", pa.int32()), ("floats", pa.float32())]),
+    ))
+
+
+def test_table_from_struct_array_invalid():
+    with pytest.raises(
+        TypeError,
+        match="Argument 'struct_array' has incorrect type "
+        "(expected pyarrow.lib.StructArray, got pyarrow.lib.Int64Array)",
+    ):
+        pa.Table.from_struct_array(pa.array(range(5)))
+
+
+def test_table_from_struct_array():
+    struct_array = pa.array(
+        [{"ints": 1}, {"floats": 1.0}],
+        type=pa.struct([("ints", pa.int32()), ("floats", pa.float32())]),
+    )
+    result = pa.Table.from_struct_array(struct_array)
+    assert result.equals(pa.Table.from_arrays(
+        [
+            pa.array([1, None], type=pa.int32()),
+            pa.array([None, 1.0], type=pa.float32()),
+        ], ["ints", "floats"]
+    ))
+
+
+def test_table_from_struct_array_chunked_array():
+    chunked_struct_array = pa.chunked_array(
+        [{"ints": 1}, {"floats": 1.0}],
+        type=pa.struct([("ints", pa.int32()), ("floats", pa.float32())]),
+    )

Review Comment:
   Could you check the failure?
   
   
https://github.com/apache/arrow/actions/runs/7170187805/job/19522351324?pr=38520#step:6:5851
   
   ```text
   __________________ test_table_from_struct_array_chunked_array 
__________________
   
       def test_table_from_struct_array_chunked_array():
   >       chunked_struct_array = pa.chunked_array(
               [{"ints": 1}, {"floats": 1.0}],
               type=pa.struct([("ints", pa.int32()), ("floats", pa.float32())]),
           )
   
   
opt/conda/envs/arrow/lib/python3.9/site-packages/pyarrow/tests/test_table.py:919:
 
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ 
   pyarrow/table.pxi:1381: in pyarrow.lib.chunked_array
       ???
   pyarrow/array.pxi:344: in pyarrow.lib.array
       ???
   pyarrow/array.pxi:42: in pyarrow.lib._sequence_to_array
       ???
   pyarrow/error.pxi:154: in pyarrow.lib.pyarrow_internal_check_status
       ???
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ 
   
   >   ???
   E   pyarrow.lib.ArrowTypeError: Could not convert 'i' with type str: was 
expecting tuple of (key, value) pair
   
   pyarrow/error.pxi:91: ArrowTypeError
   ```



-- 
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