From 6b4d5f7bd6d9fc5f95486b84b1c68312502d4b8b Mon Sep 17 00:00:00 2001 From: Hamidreza Sanaee Date: Fri, 10 Mar 2023 14:48:26 +0000 Subject: [PATCH 1/6] DOC update DataFrame.to_csv write modes (#51839) --- pandas/core/generic.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 003e4cc5b8b23..7321082cda6ce 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3630,9 +3630,13 @@ def to_csv( sequence should be given if the object uses MultiIndex. If False do not print fields for index names. Use index_label=False for easier importing in R. - mode : str, default 'w' - Python write mode. The available write modes are the same as - :py:func:`open`. + mode : {{'w', 'x', 'a'}}, default 'w' + Python write mode. The available write modes are: + + - 'w', opens the file for writing and truncates the file if it already exists. If the file does not exist, it creates a new file. + - 'x', opens the file for exclusive creation, meaning it will fail if the file already exists. If the file does not exist, it creates a new file. + - 'a', opens the file for writing in append mode. The data is written to the end of the file, without truncating it. If the file does not exist, it creates a new file. + encoding : str, optional A string representing the encoding to use in the output file, defaults to 'utf-8'. `encoding` is not supported if `path_or_buf` From 2262c568a7ea3b3738dc65645e991f4884eb688d Mon Sep 17 00:00:00 2001 From: Hamidreza Sanaee Date: Fri, 10 Mar 2023 15:26:58 +0000 Subject: [PATCH 2/6] DOC: style fix (#51839) --- pandas/core/generic.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7321082cda6ce..d6b6df93b2ca7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3633,9 +3633,15 @@ def to_csv( mode : {{'w', 'x', 'a'}}, default 'w' Python write mode. The available write modes are: - - 'w', opens the file for writing and truncates the file if it already exists. If the file does not exist, it creates a new file. - - 'x', opens the file for exclusive creation, meaning it will fail if the file already exists. If the file does not exist, it creates a new file. - - 'a', opens the file for writing in append mode. The data is written to the end of the file, without truncating it. If the file does not exist, it creates a new file. + - 'w', opens the file for writing and truncates the file if it + already exists. If the file does not exist, it creates a new + file. + - 'x', opens the file for exclusive creation, meaning it will fail + if the file already exists. If the file does not exist, it + creates a new file. + - 'a', opens the file for writing in append mode. The data is + written to the end of the file, without truncating it. If the + file does not exist, it creates a new file. encoding : str, optional A string representing the encoding to use in the output file, From 94ac0b7db4710ca7b6992c353df2a4aa004d6c7b Mon Sep 17 00:00:00 2001 From: Hamidreza Sanaee Date: Fri, 10 Mar 2023 20:35:15 +0000 Subject: [PATCH 3/6] DOC update DataFrame.to_csv write modes (#51839) Modify write mode descriptions and add an explanation for b and t mode. --- pandas/core/generic.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d6b6df93b2ca7..0516e9b98362a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3631,18 +3631,16 @@ def to_csv( False do not print fields for index names. Use index_label=False for easier importing in R. mode : {{'w', 'x', 'a'}}, default 'w' - Python write mode. The available write modes are: - - - 'w', opens the file for writing and truncates the file if it - already exists. If the file does not exist, it creates a new - file. - - 'x', opens the file for exclusive creation, meaning it will fail - if the file already exists. If the file does not exist, it - creates a new file. - - 'a', opens the file for writing in append mode. The data is - written to the end of the file, without truncating it. If the - file does not exist, it creates a new file. + Forwarded to either `open(mode=)` or `fsspec.open(mode=)` to control + the file opening. Typical values include: + - 'w', open for writing, truncating the file first. + - 'x', open for exclusive creation, failing if the file already exists. + - 'a', open for writing, appending to the end of file if it exists. + + Including 'b' or 't' in the mode parameter will inform Pandas whether + 'path_or_buf' requires string or binary data. However, in most cases, + this should not be necessary. encoding : str, optional A string representing the encoding to use in the output file, defaults to 'utf-8'. `encoding` is not supported if `path_or_buf` From 0e2636331650b4ffee2bff3f8c3395d2e5e6d1cc Mon Sep 17 00:00:00 2001 From: Hamidreza Sanaee Date: Mon, 13 Mar 2023 13:38:34 +0000 Subject: [PATCH 4/6] DOC: update DataFrame.to_csv write modes (#51839) Put path_or_buf in backticks. --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0516e9b98362a..47157fa536ef7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3639,7 +3639,7 @@ def to_csv( - 'a', open for writing, appending to the end of file if it exists. Including 'b' or 't' in the mode parameter will inform Pandas whether - 'path_or_buf' requires string or binary data. However, in most cases, + `path_or_buf` requires string or binary data. However, in most cases, this should not be necessary. encoding : str, optional A string representing the encoding to use in the output file, From c609257fae423e38c7d77fde29bfe88d8dd75316 Mon Sep 17 00:00:00 2001 From: Hamidreza Sanaee Date: Wed, 15 Mar 2023 14:27:58 +0000 Subject: [PATCH 5/6] DOC: update DataFrame.to_csv write modes (#51839) Remove the 'b' and 't' modes from the description. --- pandas/core/generic.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3212848817325..ddf5814c55b79 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3643,9 +3643,6 @@ def to_csv( - 'x', open for exclusive creation, failing if the file already exists. - 'a', open for writing, appending to the end of file if it exists. - Including 'b' or 't' in the mode parameter will inform Pandas whether - `path_or_buf` requires string or binary data. However, in most cases, - this should not be necessary. encoding : str, optional A string representing the encoding to use in the output file, defaults to 'utf-8'. `encoding` is not supported if `path_or_buf` From 51a5bbfa5779558ee1318b237ea75bf82dc04e29 Mon Sep 17 00:00:00 2001 From: Hamidreza Sanaee Date: Fri, 17 Mar 2023 14:55:43 +0000 Subject: [PATCH 6/6] DOC: update DataFrame.to_csv write modes (#51839) Modify 'w', 'a', and 'x' write mode's description. --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ddf5814c55b79..cbe270d143aee 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3639,9 +3639,9 @@ def to_csv( Forwarded to either `open(mode=)` or `fsspec.open(mode=)` to control the file opening. Typical values include: - - 'w', open for writing, truncating the file first. - - 'x', open for exclusive creation, failing if the file already exists. - - 'a', open for writing, appending to the end of file if it exists. + - 'w', truncate the file first. + - 'x', exclusive creation, failing if the file already exists. + - 'a', append to the end of file if it exists. encoding : str, optional A string representing the encoding to use in the output file,