Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): Pass missing user params in write_csv #18845

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,22 @@ def write_csv(

def write_csv_to_string() -> str:
with BytesIO() as buf:
self.write_csv(buf)
self.write_csv(
buf,
include_bom=include_bom,
include_header=include_header,
separator=separator,
line_terminator=line_terminator,
quote_char=quote_char,
batch_size=batch_size,
datetime_format=datetime_format,
date_format=date_format,
time_format=time_format,
float_scientific=float_scientific,
float_precision=float_precision,
null_value=null_value,
quote_style=quote_style,
)
csv_bytes = buf.getvalue()
return csv_bytes.decode("utf8")

Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/unit/io/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,17 @@ def test_write_csv_appending_17543(tmp_path: Path) -> None:
assert pl.read_csv(f).equals(df)


def test_write_csv_passing_params_18825() -> None:
df = pl.DataFrame({"c1": [1, 2], "c2": [3, 4]})
buffer = io.StringIO()
df.write_csv(buffer, separator="\t", include_header=False)

result_str = buffer.getvalue()
expected_str = "1\t3\n2\t4\n"

assert result_str == expected_str


@pytest.mark.parametrize(
("dtype", "df"),
[
Expand Down