Skip to content

Commit 157a65e

Browse files
DEPR: Deprecate mangle_dupe_cols (#48137)
* DEPR: Deprecate mangle_dupe_cols * Add read_table to whatsnew
1 parent 72f415b commit 157a65e

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ Other Deprecations
847847
- Deprecated the ``inplace`` keyword in :meth:`DataFrame.set_index`, use ``df = df.set_index(..., copy=False)`` instead (:issue:`48115`)
848848
- Deprecated the ``sort_columns`` argument in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`).
849849
- Deprecated positional arguments for all but the first argument of :meth:`DataFrame.to_stata` and :func:`read_stata`, use keyword arguments instead (:issue:`48128`).
850+
- Deprecated the ``mangle_dupe_cols`` argument in :func:`read_csv`, :func:`read_fwf`, :func:`read_table` and :func:`read_excel`. The argument was never implemented, and a new argument where the renaming pattern can be specified will be added instead (:issue:`47718`)
850851

851852
.. ---------------------------------------------------------------------------
852853
.. _whatsnew_150.performance:

pandas/io/excel/_base.py

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from pandas.errors import EmptyDataError
4343
from pandas.util._decorators import (
4444
Appender,
45+
deprecate_kwarg,
4546
deprecate_nonkeyword_arguments,
4647
doc,
4748
)
@@ -280,6 +281,11 @@
280281
Duplicate columns will be specified as 'X', 'X.1', ...'X.N', rather than
281282
'X'...'X'. Passing in False will cause data to be overwritten if there
282283
are duplicate names in the columns.
284+
285+
.. deprecated:: 1.5.0
286+
Not implemented, and a new argument to specify the pattern for the
287+
names of duplicated columns will be added instead
288+
283289
{storage_options}
284290
285291
.. versionadded:: 1.2.0
@@ -433,6 +439,7 @@ def read_excel(
433439

434440

435441
@doc(storage_options=_shared_docs["storage_options"])
442+
@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
436443
@deprecate_nonkeyword_arguments(allowed_args=["io", "sheet_name"], version="2.0")
437444
@Appender(_read_excel_doc)
438445
def read_excel(

pandas/io/parsers/readers.py

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from pandas.util._decorators import (
4141
Appender,
42+
deprecate_kwarg,
4243
deprecate_nonkeyword_arguments,
4344
)
4445
from pandas.util._exceptions import find_stack_level
@@ -163,6 +164,10 @@
163164
Duplicate columns will be specified as 'X', 'X.1', ...'X.N', rather than
164165
'X'...'X'. Passing in False will cause data to be overwritten if there
165166
are duplicate names in the columns.
167+
168+
.. deprecated:: 1.5.0
169+
Not implemented, and a new argument to specify the pattern for the
170+
names of duplicated columns will be added instead
166171
dtype : Type name or dict of column -> type, optional
167172
Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32,
168173
'c': 'Int64'}}
@@ -846,6 +851,7 @@ def read_csv(
846851
...
847852

848853

854+
@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
849855
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
850856
@Appender(
851857
_doc_read_csv_and_table.format(
@@ -1184,6 +1190,7 @@ def read_table(
11841190
...
11851191

11861192

1193+
@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
11871194
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
11881195
@Appender(
11891196
_doc_read_csv_and_table.format(

pandas/tests/io/excel/test_writers.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,12 @@ def test_duplicated_columns(self, path):
973973
tm.assert_frame_equal(result, expected)
974974

975975
# Explicitly, we pass in the parameter.
976-
result = pd.read_excel(
977-
path, sheet_name="test1", index_col=0, mangle_dupe_cols=True
978-
)
976+
with tm.assert_produces_warning(
977+
FutureWarning, match="the 'mangle_dupe_cols' keyword is deprecated"
978+
):
979+
result = pd.read_excel(
980+
path, sheet_name="test1", index_col=0, mangle_dupe_cols=True
981+
)
979982
tm.assert_frame_equal(result, expected)
980983

981984
# see gh-11007, gh-10970
@@ -996,8 +999,13 @@ def test_duplicated_columns(self, path):
996999
tm.assert_frame_equal(result, expected)
9971000

9981001
msg = "Setting mangle_dupe_cols=False is not supported yet"
999-
with pytest.raises(ValueError, match=msg):
1000-
pd.read_excel(path, sheet_name="test1", header=None, mangle_dupe_cols=False)
1002+
with tm.assert_produces_warning(
1003+
FutureWarning, match="the 'mangle_dupe_cols' keyword is deprecated"
1004+
):
1005+
with pytest.raises(ValueError, match=msg):
1006+
pd.read_excel(
1007+
path, sheet_name="test1", header=None, mangle_dupe_cols=False
1008+
)
10011009

10021010
def test_swapped_columns(self, path):
10031011
# Test for issue #5427.

pandas/tests/io/parser/test_mangle_dupes.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ def test_basic(all_parsers, kwargs):
2121
parser = all_parsers
2222

2323
data = "a,a,b,b,b\n1,2,3,4,5"
24-
result = parser.read_csv(StringIO(data), sep=",", **kwargs)
24+
if "mangle_dupe_cols" in kwargs:
25+
with tm.assert_produces_warning(
26+
FutureWarning,
27+
match="the 'mangle_dupe_cols' keyword is deprecated",
28+
check_stacklevel=False,
29+
):
30+
result = parser.read_csv(StringIO(data), sep=",", **kwargs)
31+
else:
32+
result = parser.read_csv(StringIO(data), sep=",", **kwargs)
2533

2634
expected = DataFrame([[1, 2, 3, 4, 5]], columns=["a", "a.1", "b", "b.1", "b.2"])
2735
tm.assert_frame_equal(result, expected)

pandas/tests/io/parser/test_unsupported.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ def test_mangle_dupe_cols_false(self):
3737
msg = "is not supported"
3838

3939
for engine in ("c", "python"):
40-
with pytest.raises(ValueError, match=msg):
41-
read_csv(StringIO(data), engine=engine, mangle_dupe_cols=False)
40+
with tm.assert_produces_warning(
41+
FutureWarning, match="the 'mangle_dupe_cols' keyword is deprecated"
42+
):
43+
with pytest.raises(ValueError, match=msg):
44+
read_csv(StringIO(data), engine=engine, mangle_dupe_cols=False)
4245

4346
def test_c_engine(self):
4447
# see gh-6607

0 commit comments

Comments
 (0)