You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "westonpace (via GitHub)" <gi...@apache.org> on 2023/07/06 14:22:23 UTC

[GitHub] [arrow] westonpace commented on a diff in pull request #36266: GH-35901: [C++][Python] pyarrow.csv.write_csv crashes when writing tables containing FixedSizeBinaryArray

westonpace commented on code in PR #36266:
URL: https://github.com/apache/arrow/pull/36266#discussion_r1254516487


##########
python/pyarrow/tests/test_csv.py:
##########
@@ -1968,3 +1968,27 @@ def test_write_csv_decimal(tmpdir, type_factory):
     out = read_csv(tmpdir / "out.csv")
 
     assert out.column('col').cast(type) == table.column('col')
+
+
+@pytest.mark.parametrize("data_size", (
+    int(1E2),
+    int(1E4),
+    int(1E6)
+))
+def test_large_binary_write_to_csv(tmpdir, data_size):
+    file_name = tmpdir / "fixedsize_"+str(data_size)+".csv"
+
+    nparr = np.frombuffer(np.random.randint(65, 91, data_size, 'u1'), 'S4')
+
+    fixed_arr = pa.array(nparr, pa.binary(4))
+    fixed_table = pa.Table.from_arrays([fixed_arr], names=['fixedsize'])
+
+    csvoption = WriteOptions(include_header=True, batch_size=2048,
+                             delimiter='|', quoting_style='none')
+
+    write_csv(fixed_table, file_name, write_options=csvoption)
+
+    assert os.path.exists(file_name)
+
+    res_table = read_csv(file_name)
+    assert fixed_table.shape, res_table.shape

Review Comment:
   ```suggestion
       assert fixed_table.shape == res_table.shape
   ```
   
   Also, why not compare the tables themselves and not just the shape?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org