diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index ab3987c8c74a4..07243b3c82e48 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -537,6 +537,7 @@ Other Deprecations - Deprecated passing arguments as positional for :func:`read_fwf` other than ``filepath_or_buffer`` (:issue:`41485`): - Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`) - Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`) +- Deprecated parameter ``names`` in :meth:`Index.copy` (:issue:`44916`) - A deprecation warning is now shown for :meth:`DataFrame.to_latex` indicating the arguments signature may change and emulate more the arguments to :meth:`.Styler.to_latex` in future versions (:issue:`44411`) - diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 54a13c124c13a..a28d3fe35ed69 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1178,6 +1178,9 @@ def copy( names : list-like, optional Kept for compatibility with MultiIndex. Should not be used. + .. deprecated:: 1.4.0 + use ``name`` instead. + Returns ------- Index @@ -1188,6 +1191,14 @@ def copy( In most cases, there should be no functional difference from using ``deep``, but if ``deep`` is passed it will attempt to deepcopy. """ + if names is not None: + warnings.warn( + "parameter names is deprecated and will be removed in a future " + "version. Use the name parameter instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = self._validate_names(name=name, names=names, deep=deep)[0] if deep: new_data = self._data.copy() diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 72d654f6cfa28..c74a566cc573d 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1260,13 +1260,19 @@ def test_copy_name2(self): assert index.name == "MyName" assert index2.name == "NewName" - index3 = index.copy(names=["NewName"]) + with tm.assert_produces_warning(FutureWarning): + index3 = index.copy(names=["NewName"]) tm.assert_index_equal(index, index3, check_names=False) assert index.name == "MyName" assert index.names == ["MyName"] assert index3.name == "NewName" assert index3.names == ["NewName"] + def test_copy_names_deprecated(self, simple_index): + # GH44916 + with tm.assert_produces_warning(FutureWarning): + simple_index.copy(names=["a"]) + def test_unique_na(self): idx = Index([2, np.nan, 2, 1], name="my_index") expected = Index([2, np.nan, 1], name="my_index")