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:2049–2090  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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