Skip to content

Commit

Permalink
Use "sep" instead of "delimiter" in pl.Dataframe().to_csv().
Browse files Browse the repository at this point in the history
Use "sep" instead of "delimiter" in pl.Dataframe().to_csv()
to be constent with pl.read_csv() and pl.scan_csv().
  • Loading branch information
ghuls authored and ritchie46 committed Sep 22, 2021
1 parent 3c1f8a4 commit 857b3b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions py-polars/polars/eager/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def to_csv(
self,
file: Optional[Union[TextIO, str, Path]] = None,
has_headers: bool = True,
delimiter: str = ",",
sep: str = ",",
) -> Optional[str]:
"""
Write Dataframe to comma-separated values file (csv).
Expand All @@ -779,7 +779,7 @@ def to_csv(
File path to which the file should be written.
has_headers
Whether or not to include header in the CSV output.
delimiter
sep
Separate CSV fields with this symbol.
Examples
Expand All @@ -795,13 +795,13 @@ def to_csv(
"""
if file is None:
buffer = BytesIO()
self._df.to_csv(buffer, has_headers, ord(delimiter))
self._df.to_csv(buffer, has_headers, ord(sep))
return str(buffer.getvalue(), encoding="utf-8")

if isinstance(file, Path):
file = str(file)

self._df.to_csv(file, has_headers, ord(delimiter))
self._df.to_csv(file, has_headers, ord(sep))
return None

def to_ipc(self, file: Union[BinaryIO, str, Path]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ impl PyDataFrame {
Ok(pydf)
}

pub fn to_csv(&self, py_f: PyObject, has_headers: bool, delimiter: u8) -> PyResult<()> {
pub fn to_csv(&self, py_f: PyObject, has_headers: bool, sep: u8) -> PyResult<()> {
let mut buf = get_file_like(py_f, true)?;
CsvWriter::new(&mut buf)
.has_headers(has_headers)
.with_delimiter(delimiter)
.with_delimiter(sep)
.finish(&self.df)
.map_err(PyPolarsEr::from)?;
Ok(())
Expand Down

0 comments on commit 857b3b2

Please sign in to comment.