()
| 1977 | |
| 1978 | |
| 1979 | def test_write_read_round_trip(): |
| 1980 | t = pa.Table.from_arrays([[1, 2, 3], ["a", "b", "c"]], ["c1", "c2"]) |
| 1981 | record_batch = t.to_batches(max_chunksize=4)[0] |
| 1982 | for data in [t, record_batch]: |
| 1983 | # Test with header |
| 1984 | buf = io.BytesIO() |
| 1985 | write_csv(data, buf, WriteOptions(include_header=True)) |
| 1986 | buf.seek(0) |
| 1987 | assert t == read_csv(buf) |
| 1988 | |
| 1989 | # Test without header |
| 1990 | buf = io.BytesIO() |
| 1991 | write_csv(data, buf, WriteOptions(include_header=False)) |
| 1992 | buf.seek(0) |
| 1993 | |
| 1994 | read_options = ReadOptions(column_names=t.column_names) |
| 1995 | assert t == read_csv(buf, read_options=read_options) |
| 1996 | |
| 1997 | # Test with writer |
| 1998 | for read_options, parse_options, write_options in [ |
| 1999 | (None, None, WriteOptions(include_header=True)), |
| 2000 | (ReadOptions(column_names=t.column_names), None, |
| 2001 | WriteOptions(include_header=False)), |
| 2002 | (None, ParseOptions(delimiter='|'), |
| 2003 | WriteOptions(include_header=True, delimiter='|')), |
| 2004 | (ReadOptions(column_names=t.column_names), |
| 2005 | ParseOptions(delimiter='\t'), |
| 2006 | WriteOptions(include_header=False, delimiter='\t')), |
| 2007 | ]: |
| 2008 | buf = io.BytesIO() |
| 2009 | with CSVWriter(buf, t.schema, write_options=write_options) as writer: |
| 2010 | writer.write_table(t) |
| 2011 | buf.seek(0) |
| 2012 | assert t == read_csv(buf, read_options=read_options, |
| 2013 | parse_options=parse_options) |
| 2014 | buf = io.BytesIO() |
| 2015 | with CSVWriter(buf, t.schema, write_options=write_options) as writer: |
| 2016 | for batch in t.to_batches(max_chunksize=1): |
| 2017 | writer.write_batch(batch) |
| 2018 | buf.seek(0) |
| 2019 | assert t == read_csv(buf, read_options=read_options, |
| 2020 | parse_options=parse_options) |
| 2021 | |
| 2022 | |
| 2023 | def test_write_quoting_style(): |
nothing calls this directly
no test coverage detected