Skip to content

TST: Test DataFrame rename with ChainMap #29306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import ChainMap
from datetime import datetime, timedelta
import inspect

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

@pytest.mark.parametrize(
"args,kwargs",
[
((ChainMap({"A": "a"}, {"B": "b"}),), dict(axis="columns")),
((), dict(columns=ChainMap({"A": "a"}, {"B": "b"}))),
],
)
def test_rename_chainmap(self, args, kwargs):
# see gh-23859
colAData = range(1, 11)
colBdata = np.random.randn(10)

df = DataFrame({"A": colAData, "B": colBdata})
result = df.rename(*args, **kwargs)

expected = DataFrame({"a": colAData, "b": colBdata})
tm.assert_frame_equal(result, expected)

def test_rename_axis_inplace(self, float_frame):
# GH 15704
expected = float_frame.rename_axis("foo")
Expand Down