Skip to content

Commit 05fe1dc

Browse files
meeseeksmachinejorisvandenbossche
authored andcommitted
Backport PR #25624: DOC: file obj for to_csv must be newline='' (#25659)
1 parent f70f2b6 commit 05fe1dc

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: doc/source/user_guide/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ The ``Series`` and ``DataFrame`` objects have an instance method ``to_csv`` whic
16891689
allows storing the contents of the object as a comma-separated-values file. The
16901690
function takes a number of arguments. Only the first is required.
16911691

1692-
* ``path_or_buf``: A string path to the file to write or a StringIO
1692+
* ``path_or_buf``: A string path to the file to write or a file object. If a file object it must be opened with `newline=''`
16931693
* ``sep`` : Field delimiter for the output file (default ",")
16941694
* ``na_rep``: A string representation of a missing value (default '')
16951695
* ``float_format``: Format string for floating point numbers
@@ -1702,7 +1702,7 @@ function takes a number of arguments. Only the first is required.
17021702
* ``mode`` : Python write mode, default 'w'
17031703
* ``encoding``: a string representing the encoding to use if the contents are
17041704
non-ASCII, for Python versions prior to 3
1705-
* ``line_terminator``: Character sequence denoting line end (default '\\n')
1705+
* ``line_terminator``: Character sequence denoting line end (default `os.linesep`)
17061706
* ``quoting``: Set quoting rules as in csv module (default csv.QUOTE_MINIMAL). Note that if you have set a `float_format` then floats are converted to strings and csv.QUOTE_NONNUMERIC will treat them as non-numeric
17071707
* ``quotechar``: Character used to quote fields (default '"')
17081708
* ``doublequote``: Control quoting of ``quotechar`` in fields (default True)

Diff for: pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,8 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
28952895
----------
28962896
path_or_buf : str or file handle, default None
28972897
File path or object, if None is provided the result is returned as
2898-
a string.
2898+
a string. If a file object is passed it should be opened with
2899+
`newline=''`, disabling universal newlines.
28992900
29002901
.. versionchanged:: 0.24.0
29012902

0 commit comments

Comments
 (0)