Skip to content

Commit 6ba8d46

Browse files
committed
DEPR: Deprecate tupleize_cols in read_csv
xref pandas-devgh-17060.
1 parent f9ba6fe commit 6ba8d46

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

Diff for: doc/source/io.rst

+4
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ dialect : str or :class:`python:csv.Dialect` instance, default ``None``
343343
override values, a ParserWarning will be issued. See :class:`python:csv.Dialect`
344344
documentation for more details.
345345
tupleize_cols : boolean, default ``False``
346+
.. deprecated:: 0.21.0
347+
348+
This argument will be removed and will always convert to MultiIndex
349+
346350
Leave a list of tuples on columns as is (default is to convert to a MultiIndex
347351
on the columns).
348352

Diff for: doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ Deprecations
716716

717717
- :func:`read_excel()` has deprecated ``sheetname`` in favor of ``sheet_name`` for consistency with ``.to_excel()`` (:issue:`10559`).
718718
- :func:`read_excel()` has deprecated ``parse_cols`` in favor of ``usecols`` for consistency with :func:`read_csv` (:issue:`4988`)
719+
- :func:`read_csv()` has deprecated the ``tupleize_cols`` argument (:issue:`17060`)
719720
- The ``convert`` parameter has been deprecated in the ``.take()`` method, as it was not being respected (:issue:`16948`)
720721
- ``pd.options.html.border`` has been deprecated in favor of ``pd.options.display.html.border`` (:issue:`15793`).
721722
- :func:`SeriesGroupBy.nth` has deprecated ``True`` in favor of ``'all'`` for its kwarg ``dropna`` (:issue:`11038`).

Diff for: pandas/io/parsers.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@
260260
override values, a ParserWarning will be issued. See csv.Dialect
261261
documentation for more details.
262262
tupleize_cols : boolean, default False
263+
.. deprecated:: 0.21.0
264+
This argument will be removed and will always convert to MultiIndex
265+
263266
Leave a list of tuples on columns as is (default is to convert to
264-
a Multi Index on the columns)
267+
a MultiIndex on the columns)
265268
error_bad_lines : boolean, default True
266269
Lines with too many fields (e.g. a csv line with too many commas) will by
267270
default cause an exception to be raised, and no DataFrame will be returned.
@@ -510,6 +513,7 @@ def _read(filepath_or_buffer, kwds):
510513
'buffer_lines': None,
511514
'error_bad_lines': True,
512515
'warn_bad_lines': True,
516+
'tupleize_cols': False,
513517
'float_precision': None
514518
}
515519

@@ -529,6 +533,7 @@ def _read(filepath_or_buffer, kwds):
529533
'buffer_lines',
530534
'compact_ints',
531535
'use_unsigned',
536+
'tupleize_cols'
532537
}
533538

534539

@@ -962,6 +967,9 @@ def _clean_options(self, options, engine):
962967

963968
if arg == 'as_recarray':
964969
msg += ' Please call pd.to_csv(...).to_records() instead.'
970+
elif arg == 'tupleize_cols':
971+
msg += (' Column tuples will then '
972+
'always be converted to MultiIndex')
965973

966974
if result.get(arg, parser_default) != parser_default:
967975
depr_warning += msg + '\n\n'

Diff for: pandas/tests/io/parser/header.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def test_header_multi_index(self):
105105
R_l0_g4,R_l1_g4,R4C0,R4C1,R4C2
106106
"""
107107

108-
df = self.read_csv(StringIO(data), header=[0, 1, 2, 3], index_col=[
109-
0, 1], tupleize_cols=False)
108+
df = self.read_csv(StringIO(data), header=[0, 1, 2, 3],
109+
index_col=[0, 1])
110110
tm.assert_frame_equal(df, expected)
111111

112112
# skipping lines in the header
113-
df = self.read_csv(StringIO(data), header=[0, 1, 2, 3], index_col=[
114-
0, 1], tupleize_cols=False)
113+
df = self.read_csv(StringIO(data), header=[0, 1, 2, 3],
114+
index_col=[0, 1])
115115
tm.assert_frame_equal(df, expected)
116116

117117
# INVALID OPTIONS
@@ -121,25 +121,22 @@ def test_header_multi_index(self):
121121
FutureWarning, check_stacklevel=False):
122122
pytest.raises(ValueError, self.read_csv,
123123
StringIO(data), header=[0, 1, 2, 3],
124-
index_col=[0, 1], as_recarray=True,
125-
tupleize_cols=False)
124+
index_col=[0, 1], as_recarray=True)
126125

127126
# names
128127
pytest.raises(ValueError, self.read_csv,
129128
StringIO(data), header=[0, 1, 2, 3],
130-
index_col=[0, 1], names=['foo', 'bar'],
131-
tupleize_cols=False)
129+
index_col=[0, 1], names=['foo', 'bar'])
132130

133131
# usecols
134132
pytest.raises(ValueError, self.read_csv,
135133
StringIO(data), header=[0, 1, 2, 3],
136-
index_col=[0, 1], usecols=['foo', 'bar'],
137-
tupleize_cols=False)
134+
index_col=[0, 1], usecols=['foo', 'bar'])
138135

139136
# non-numeric index_col
140137
pytest.raises(ValueError, self.read_csv,
141138
StringIO(data), header=[0, 1, 2, 3],
142-
index_col=['foo', 'bar'], tupleize_cols=False)
139+
index_col=['foo', 'bar'])
143140

144141
def test_header_multiindex_common_format(self):
145142

Diff for: pandas/tests/io/parser/python_parser_only.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ def test_none_delimiter(self):
232232
result = self.read_csv(StringIO(data), header=0,
233233
sep=None,
234234
error_bad_lines=False,
235-
warn_bad_lines=True,
236-
engine='python',
237-
tupleize_cols=True)
235+
warn_bad_lines=True)
238236
tm.assert_frame_equal(result, expected)
239237

240238
def test_skipfooter_bad_row(self):

Diff for: pandas/tests/io/parser/test_unsupported.py

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_deprecated_args(self):
136136
'buffer_lines': True,
137137
'compact_ints': True,
138138
'use_unsigned': True,
139+
'tupleize_cols': True,
139140
'skip_footer': 1,
140141
}
141142

0 commit comments

Comments
 (0)