MCPcopy Create free account
hub / github.com/apache/arrow / test_write_read_round_trip

Function test_write_read_round_trip

python/pyarrow/tests/test_csv.py:2050–2091  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2048
2049
2050def test_write_read_round_trip():
2051 t = pa.Table.from_arrays([[1, 2, 3], ["a", "b", "c"]], ["c1", "c2"])
2052 record_batch = t.to_batches(max_chunksize=4)[0]
2053 for data in [t, record_batch]:
2054 # Test with header
2055 buf = io.BytesIO()
2056 write_csv(data, buf, WriteOptions(include_header=True))
2057 buf.seek(0)
2058 assert t == read_csv(buf)
2059
2060 # Test without header
2061 buf = io.BytesIO()
2062 write_csv(data, buf, WriteOptions(include_header=False))
2063 buf.seek(0)
2064
2065 read_options = ReadOptions(column_names=t.column_names)
2066 assert t == read_csv(buf, read_options=read_options)
2067
2068 # Test with writer
2069 for read_options, parse_options, write_options in [
2070 (None, None, WriteOptions(include_header=True)),
2071 (ReadOptions(column_names=t.column_names), None,
2072 WriteOptions(include_header=False)),
2073 (None, ParseOptions(delimiter='|'),
2074 WriteOptions(include_header=True, delimiter='|')),
2075 (ReadOptions(column_names=t.column_names),
2076 ParseOptions(delimiter='\t'),
2077 WriteOptions(include_header=False, delimiter='\t')),
2078 ]:
2079 buf = io.BytesIO()
2080 with CSVWriter(buf, t.schema, write_options=write_options) as writer:
2081 writer.write_table(t)
2082 buf.seek(0)
2083 assert t == read_csv(buf, read_options=read_options,
2084 parse_options=parse_options)
2085 buf = io.BytesIO()
2086 with CSVWriter(buf, t.schema, write_options=write_options) as writer:
2087 for batch in t.to_batches(max_chunksize=1):
2088 writer.write_batch(batch)
2089 buf.seek(0)
2090 assert t == read_csv(buf, read_options=read_options,
2091 parse_options=parse_options)
2092
2093
2094def test_write_quoting_style():

Callers

nothing calls this directly

Calls 7

WriteOptionsClass · 0.90
ReadOptionsClass · 0.90
ParseOptionsClass · 0.90
to_batchesMethod · 0.80
seekMethod · 0.80
write_batchMethod · 0.80
write_tableMethod · 0.45

Tested by

no test coverage detected