Skip to content

Commit

Permalink
fix csv writer delimiter (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Mar 5, 2022
1 parent e2def1c commit da4b3ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions polars/polars-io/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ use std::path::PathBuf;
pub struct CsvWriter<W: Write> {
/// File or Stream handler
buffer: W,
/// Builds an Arrow CSV Writer
writer_builder: write::WriterBuilder,
/// arrow specific options
options: write::SerializeOptions,
header: bool,
Expand All @@ -83,7 +81,6 @@ where

CsvWriter {
buffer,
writer_builder: write::WriterBuilder::new(),
options,
header: true,
}
Expand Down Expand Up @@ -115,7 +112,7 @@ where

/// Set the CSV file's column delimiter as a byte character
pub fn with_delimiter(mut self, delimiter: u8) -> Self {
self.writer_builder.delimiter(delimiter);
self.options.delimiter = delimiter;
self
}

Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/io/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,11 @@ def test_empty_string_missing_round_trip() -> None:
f.seek(0)
df_read = pl.read_csv(f)
assert df.frame_equal(df_read)


def test_write_csv_delimiter() -> None:
df = pl.DataFrame({"a": [1, 2, 3], "b": [1, 2, 3]})
f = io.BytesIO()
df.to_csv(f, sep="\t")
f.seek(0)
assert f.read() == b"a\tb\n1\t1\n2\t2\n3\t3\n"

0 comments on commit da4b3ab

Please sign in to comment.