Skip to content

Commit 34978a7

Browse files
gfyoungjreback
authored andcommitted
DEPR: Deprecate tupleize_cols in to_csv (pandas-dev#17877)
1 parent a2ff3f0 commit 34978a7

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ Deprecations
803803
- :func:`read_excel()` has deprecated ``sheetname`` in favor of ``sheet_name`` for consistency with ``.to_excel()`` (:issue:`10559`).
804804
- :func:`read_excel()` has deprecated ``parse_cols`` in favor of ``usecols`` for consistency with :func:`read_csv` (:issue:`4988`)
805805
- :func:`read_csv()` has deprecated the ``tupleize_cols`` argument. Column tuples will always be converted to a ``MultiIndex`` (:issue:`17060`)
806+
- :meth:`DataFrame.to_csv` has deprecated the ``tupleize_cols`` argument. Multi-index columns will be always written as rows in the CSV file (:issue:`17060`)
806807
- The ``convert`` parameter has been deprecated in the ``.take()`` method, as it was not being respected (:issue:`16948`)
807808
- ``pd.options.html.border`` has been deprecated in favor of ``pd.options.display.html.border`` (:issue:`15793`).
808809
- :func:`SeriesGroupBy.nth` has deprecated ``True`` in favor of ``'all'`` for its kwarg ``dropna`` (:issue:`11038`).

pandas/core/frame.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
14321432
columns=None, header=True, index=True, index_label=None,
14331433
mode='w', encoding=None, compression=None, quoting=None,
14341434
quotechar='"', line_terminator='\n', chunksize=None,
1435-
tupleize_cols=False, date_format=None, doublequote=True,
1435+
tupleize_cols=None, date_format=None, doublequote=True,
14361436
escapechar=None, decimal='.'):
14371437
r"""Write DataFrame to a comma-separated values (csv) file
14381438
@@ -1485,15 +1485,28 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
14851485
chunksize : int or None
14861486
rows to write at a time
14871487
tupleize_cols : boolean, default False
1488-
write multi_index columns as a list of tuples (if True)
1489-
or new (expanded format) if False)
1488+
.. deprecated:: 0.21.0
1489+
This argument will be removed and will always write each row
1490+
of the multi-index as a separate row in the CSV file.
1491+
1492+
Write MultiIndex columns as a list of tuples (if True) or in
1493+
the new, expanded format, where each MultiIndex column is a row
1494+
in the CSV (if False).
14901495
date_format : string, default None
14911496
Format string for datetime objects
14921497
decimal: string, default '.'
14931498
Character recognized as decimal separator. E.g. use ',' for
14941499
European data
14951500
14961501
"""
1502+
1503+
if tupleize_cols is not None:
1504+
warnings.warn("The 'tupleize_cols' parameter is deprecated and "
1505+
"will be removed in a future version",
1506+
FutureWarning, stacklevel=2)
1507+
else:
1508+
tupleize_cols = False
1509+
14971510
formatter = fmt.CSVFormatter(self, path_or_buf,
14981511
line_terminator=line_terminator, sep=sep,
14991512
encoding=encoding,

pandas/tests/frame/test_to_csv.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ def _make_frame(names=None):
577577

578578
# tupleize_cols=True and index=False
579579
df = _make_frame(True)
580-
df.to_csv(path, tupleize_cols=True, index=False)
580+
with tm.assert_produces_warning(FutureWarning):
581+
df.to_csv(path, tupleize_cols=True, index=False)
581582

582583
with tm.assert_produces_warning(FutureWarning,
583584
check_stacklevel=False):
@@ -602,7 +603,8 @@ def _make_frame(names=None):
602603

603604
# column & index are multi-index (compatibility)
604605
df = mkdf(5, 3, r_idx_nlevels=2, c_idx_nlevels=4)
605-
df.to_csv(path, tupleize_cols=True)
606+
with tm.assert_produces_warning(FutureWarning):
607+
df.to_csv(path, tupleize_cols=True)
606608

607609
with tm.assert_produces_warning(FutureWarning,
608610
check_stacklevel=False):

0 commit comments

Comments
 (0)