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


##########
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)",

Review Comment:
   It seems that we need to add `re.escape()` like `match=re.escape("Argument 
...")` because the message includes some special characters for regular 
expression such as `(` and `.`.
   
   
https://github.com/apache/arrow/actions/runs/7170187805/job/19522351324?pr=38520#step:6:5817
   
   ```text
   =================================== FAILURES 
===================================
   _____________________ test_table_from_struct_array_invalid 
_____________________
   
       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)))
   
   
opt/conda/envs/arrow/lib/python3.9/site-packages/pyarrow/tests/test_table.py:901:
 
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ 
   
   >   ???
   E   TypeError: Argument 'struct_array' has incorrect type (expected 
pyarrow.lib.StructArray, got pyarrow.lib.Int64Array)
   
   pyarrow/table.pxi:4022: TypeError
   
   During handling of the above exception, another exception occurred:
   
       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)))
   E           AssertionError: Regex pattern did not match.
   E            Regex: "Argument 'struct_array' has incorrect type (expected 
pyarrow.lib.StructArray, got pyarrow.lib.Int64Array)"
   E            Input: "Argument 'struct_array' has incorrect type (expected 
pyarrow.lib.StructArray, got pyarrow.lib.Int64Array)"
   E            Did you mean to `re.escape()` the regex?
   
   
opt/conda/envs/arrow/lib/python3.9/site-packages/pyarrow/tests/test_table.py:901:
 AssertionError
   ```



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