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