Skip to content
Merged
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
8 changes: 5 additions & 3 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,12 +1046,14 @@ def to_csv(
"""
from pandas.io.formats.csvs import CSVFormatter

created_buffer = path_or_buf is None
if created_buffer:
if path_or_buf is None:
created_buffer = True
path_or_buf = StringIO()
else:
created_buffer = False

csv_formatter = CSVFormatter(
path_or_buf=path_or_buf, # type: ignore[arg-type]
path_or_buf=path_or_buf,
line_terminator=line_terminator,
sep=sep,
encoding=encoding,
Expand Down