Description
Is your feature request related to a problem?
The df.to_csv()
function has a mode
parameter that allows the user to specify the file mode when writing.
I usually use mode='x'
to avoid writing over the existing file, as caution.
Is there any specific reason why to_pickle
and co. doesn't have the same parameter?
Describe the solution you'd like
I see that mode
for df.to_csv
is implemented/used via the get_handle
function: https://github.com/pandas-dev/pandas/blob/1.4.x/pandas/io/formats/csvs.py#L243
df.to_pickle
also has the same function call but mode is fixed to wb
: https://github.com/pandas-dev/pandas/blob/1.4.x/pandas/io/pickle.py#L99
Can mode
be exposed as an API to the end user, with additional checks that the user specifies binary (b
) if needed?
API breaking implications
Not sure, probably none?
Additional info
docs for to_pickle: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_pickle.html
docs for to_csv: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html
Describe alternatives you've considered
End user manually checks if file exists before running df.to_pickle
.