Skip to content

Commit 7a1b5c7

Browse files
gfyoungproost
authored andcommitted
TST: Test DataFrame rename with ChainMap (pandas-dev#29306)
1 parent 5a9d054 commit 7a1b5c7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/frame/test_alter_axes.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import ChainMap
12
from datetime import datetime, timedelta
23
import inspect
34

@@ -691,6 +692,24 @@ def test_rename(self, float_frame):
691692
tm.assert_index_equal(renamed.index, Index(["bar", "foo"], name="name"))
692693
assert renamed.index.name == renamer.index.name
693694

695+
@pytest.mark.parametrize(
696+
"args,kwargs",
697+
[
698+
((ChainMap({"A": "a"}, {"B": "b"}),), dict(axis="columns")),
699+
((), dict(columns=ChainMap({"A": "a"}, {"B": "b"}))),
700+
],
701+
)
702+
def test_rename_chainmap(self, args, kwargs):
703+
# see gh-23859
704+
colAData = range(1, 11)
705+
colBdata = np.random.randn(10)
706+
707+
df = DataFrame({"A": colAData, "B": colBdata})
708+
result = df.rename(*args, **kwargs)
709+
710+
expected = DataFrame({"a": colAData, "b": colBdata})
711+
tm.assert_frame_equal(result, expected)
712+
694713
def test_rename_axis_inplace(self, float_frame):
695714
# GH 15704
696715
expected = float_frame.rename_axis("foo")

0 commit comments

Comments
 (0)