File tree 2 files changed +20
-0
lines changed 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,20 @@ def test_copy_name(self, index):
270
270
s3 = s1 * s2
271
271
assert s3 .index .name == "mario"
272
272
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
+
273
287
def test_ensure_copied_data (self , index ):
274
288
# Check the "copy" argument of each Index.__new__ is honoured
275
289
# GH12309
Original file line number Diff line number Diff line change @@ -75,6 +75,12 @@ def test_copy_names():
75
75
assert multi_idx .names == ["MyName1" , "MyName2" ]
76
76
assert multi_idx3 .names == ["NewName1" , "NewName2" ]
77
77
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
+
78
84
79
85
def test_names (idx , index_names ):
80
86
You can’t perform that action at this time.
0 commit comments