()
| 2047 | |
| 2048 | |
| 2049 | def 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 | |
| 2093 | def test_write_quoting_style(): |
nothing calls this directly
no test coverage detected