Skip to content

Commit 7db707a

Browse files
committed
bug: reproduce #43659 in test_rename_with_multiindex at Series test.
1 parent e7e7b40 commit 7db707a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pandas/tests/generic/test_series.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,34 @@ def finalize(self, other, method=None, **kwargs):
151151
# reset
152152
Series._metadata = _metadata
153153
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

Comments
 (0)