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

Function test_write_dataset_csv

python/pyarrow/tests/test_dataset.py:4964–4987  ·  view source on GitHub ↗
(tempdir)

Source from the content-addressed store, hash-verified

4962
4963
4964def test_write_dataset_csv(tempdir):
4965 table = pa.table([
4966 pa.array(range(20)), pa.array(random.random() for _ in range(20)),
4967 pa.array(['a'] * 10 + ['b'] * 10)
4968 ], names=["f1", "f2", "chr1"])
4969
4970 base_dir = tempdir / 'csv_dataset'
4971 ds.write_dataset(table, base_dir, format="csv")
4972 # check that all files are present
4973 file_paths = list(base_dir.rglob("*"))
4974 expected_paths = [base_dir / "part-0.csv"]
4975 assert set(file_paths) == set(expected_paths)
4976 # check Table roundtrip
4977 result = ds.dataset(base_dir, format="csv").to_table()
4978 assert result.equals(table)
4979
4980 # using custom options
4981 format = ds.CsvFileFormat(read_options=pyarrow.csv.ReadOptions(
4982 column_names=table.schema.names))
4983 opts = format.make_write_options(include_header=False)
4984 base_dir = tempdir / 'csv_dataset_noheader'
4985 ds.write_dataset(table, base_dir, format=format, file_options=opts)
4986 result = ds.dataset(base_dir, format=format).to_table()
4987 assert result.equals(table)
4988
4989
4990@pytest.mark.parquet

Callers

nothing calls this directly

Calls 5

listFunction · 0.85
equalsMethod · 0.80
CsvFileFormatMethod · 0.80
arrayMethod · 0.45
to_tableMethod · 0.45

Tested by

no test coverage detected