Skip to content

Commit 8ecc92f

Browse files
committed
add tests
1 parent 41c3e9c commit 8ecc92f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/tests/indexes/common.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,20 @@ def test_copy_name(self, index):
270270
s3 = s1 * s2
271271
assert s3.index.name == "mario"
272272

273+
def test_name2(self, index):
274+
# gh-35592
275+
if isinstance(index, MultiIndex):
276+
return
277+
278+
assert index.copy(name="mario").name == "mario"
279+
280+
with pytest.raises(ValueError, match="Length of new names must be 1, got 2"):
281+
index.copy(name=["mario", "luigi"])
282+
283+
msg = f"{type(index).__name__}.name must be a hashable type"
284+
with pytest.raises(TypeError, match=msg):
285+
index.copy(name=[["mario"]])
286+
273287
def test_ensure_copied_data(self, index):
274288
# Check the "copy" argument of each Index.__new__ is honoured
275289
# GH12309

pandas/tests/indexes/multi/test_names.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ def test_copy_names():
7575
assert multi_idx.names == ["MyName1", "MyName2"]
7676
assert multi_idx3.names == ["NewName1", "NewName2"]
7777

78+
with pytest.raises(ValueError, match="Length of new names must be 2, got 1"):
79+
multi_idx.copy(names=["mario"])
80+
81+
with pytest.raises(TypeError, match="MultiIndex.name must be a hashable type"):
82+
multi_idx.copy(names=[["mario"], ["luigi"]])
83+
7884

7985
def test_names(idx, index_names):
8086

0 commit comments

Comments
 (0)