@@ -151,3 +151,34 @@ def finalize(self, other, method=None, **kwargs):
151
151
# reset
152
152
Series ._metadata = _metadata
153
153
Series .__finalize__ = _finalize # FIXME: use monkeypatch
154
+
155
+ # issue #43659
156
+ def test_rename_with_multiindex (self ):
157
+ arrays = [
158
+ ["bar" , "bar" , "baz" , "baz" , "foo" , "foo" , "qux" , "qux" ],
159
+ ["one" , "two" , "one" , "two" , "one" , "two" , "one" , "two" ]
160
+ ]
161
+
162
+ tuples = list (zip (* arrays ))
163
+ index = MultiIndex .from_tuples (tuples , names = ["first" , "second" ])
164
+ s = Series (np .ones (8 ), index = index )
165
+ s .rename (index = {'one' : 'yes' }, level = 'second' , errors = 'raise' )
166
+
167
+ arrays_expected = [
168
+ ["bar" , "bar" , "baz" , "baz" , "foo" , "foo" , "qux" , "qux" ],
169
+ ["yes" , "two" , "yes" , "two" , "yes" , "two" , "yes" , "two" ]
170
+ ]
171
+
172
+ tuples_expected = list (zip (* arrays_expected ))
173
+ index_expected = MultiIndex .from_tuples (
174
+ tuples_expected ,
175
+ names = ["first" , "second" ]
176
+ )
177
+ s_expected = Series (np .ones (8 ), index = index_expected )
178
+
179
+ assert s == s_expected
180
+
181
+
182
+
183
+
184
+
0 commit comments