You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "AlenkaF (via GitHub)" <gi...@apache.org> on 2023/11/20 08:34:53 UTC
Re: [PR] GH-35901: [C++][Python] pyarrow.csv.write_csv crashes when writing tables containing FixedSizeBinaryArray [arrow]
AlenkaF commented on code in PR #36266:
URL: https://github.com/apache/arrow/pull/36266#discussion_r1398810429
##########
python/pyarrow/tests/test_csv.py:
##########
@@ -1972,6 +1972,38 @@ def test_write_csv_decimal(tmpdir, type_factory):
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'])
+ fixed_table = fixed_table.combine_chunks()
+
+ write_options = WriteOptions(include_header=True, batch_size=2048,
+ delimiter='|')
+ write_csv(fixed_table, file_name, write_options=write_options)
+
+ assert os.path.exists(file_name)
+
+ parse_options = ParseOptions(delimiter="|")
+ convert_options = ConvertOptions(column_types={"fixedsize": pa.binary(4)})
+ read_options = ReadOptions(block_size=2048)
+
+ res_table = read_csv(file_name, parse_options=parse_options,
+ convert_options=convert_options,
+ read_options=read_options)
+ res_table = res_table.combine_chunks()
+
+ assert res_table.column(0).chunks[0] == fixed_table.column(0).chunks[0]
Review Comment:
```suggestion
if not res_table.equals(fixed_table):
# Better error output
assert res_table.to_pydict() == fixed_table.to_pydict()
```
--
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