Skip to content

Commit adfc78b

Browse files
authored
DEPR: ‘names’ param in Index.copy (pandas-dev#44916)
1 parent ccc1a25 commit adfc78b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ Other Deprecations
537537
- Deprecated passing arguments as positional for :func:`read_fwf` other than ``filepath_or_buffer`` (:issue:`41485`):
538538
- Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`)
539539
- Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`)
540+
- Deprecated parameter ``names`` in :meth:`Index.copy` (:issue:`44916`)
540541
- 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`)
541542
- Deprecated :meth:`Categorical.replace`, use :meth:`Series.replace` instead (:issue:`44929`)
542543
-

pandas/core/indexes/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,9 @@ def copy(
11781178
names : list-like, optional
11791179
Kept for compatibility with MultiIndex. Should not be used.
11801180
1181+
.. deprecated:: 1.4.0
1182+
use ``name`` instead.
1183+
11811184
Returns
11821185
-------
11831186
Index
@@ -1188,6 +1191,14 @@ def copy(
11881191
In most cases, there should be no functional difference from using
11891192
``deep``, but if ``deep`` is passed it will attempt to deepcopy.
11901193
"""
1194+
if names is not None:
1195+
warnings.warn(
1196+
"parameter names is deprecated and will be removed in a future "
1197+
"version. Use the name parameter instead.",
1198+
FutureWarning,
1199+
stacklevel=find_stack_level(),
1200+
)
1201+
11911202
name = self._validate_names(name=name, names=names, deep=deep)[0]
11921203
if deep:
11931204
new_data = self._data.copy()

pandas/tests/indexes/test_base.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1260,13 +1260,19 @@ def test_copy_name2(self):
12601260
assert index.name == "MyName"
12611261
assert index2.name == "NewName"
12621262

1263-
index3 = index.copy(names=["NewName"])
1263+
with tm.assert_produces_warning(FutureWarning):
1264+
index3 = index.copy(names=["NewName"])
12641265
tm.assert_index_equal(index, index3, check_names=False)
12651266
assert index.name == "MyName"
12661267
assert index.names == ["MyName"]
12671268
assert index3.name == "NewName"
12681269
assert index3.names == ["NewName"]
12691270

1271+
def test_copy_names_deprecated(self, simple_index):
1272+
# GH44916
1273+
with tm.assert_produces_warning(FutureWarning):
1274+
simple_index.copy(names=["a"])
1275+
12701276
def test_unique_na(self):
12711277
idx = Index([2, np.nan, 2, 1], name="my_index")
12721278
expected = Index([2, np.nan, 1], name="my_index")

0 commit comments

Comments
 (0)