Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions pandas/tests/frame/methods/test_rename_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def test_rename_axis_inplace(self, float_frame):
assert no_return is None
tm.assert_frame_equal(result, expected)

def test_rename_axis_with_allows_duplicate_labels_false(self):
# GH#44958
df = DataFrame([[1, 2], [3, 4]], columns=["a", "b"]).set_flags(
allows_duplicate_labels=False
)

result = df.rename_axis("idx", axis=0)
expected = DataFrame(
[[1, 2], [3, 4]], index=Index([0, 1], name="idx"), columns=["a", "b"]
).set_flags(allows_duplicate_labels=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment:
I think we can define the expected DataFrame without specifying set_flags. Instead, in the assertion statement we can use check_flags=False.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, looks much cleaner, thank you

tm.assert_frame_equal(result, expected)

def test_rename_axis_raises(self):
# GH#17833
df = DataFrame({"A": [1, 2], "B": [1, 2]})
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/frame/methods/test_set_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ def obj(self):
)
return df

def test_set_axis_with_allows_duplicate_labels_false(self):
# GH#44958
df = DataFrame([[1, 2], [3, 4]], columns=["a", "b"]).set_flags(
allows_duplicate_labels=False
)

result = df.set_axis(labels=["x", "y"], axis=0)
expected = DataFrame(
[[1, 2], [3, 4]], index=["x", "y"], columns=["a", "b"]
).set_flags(allows_duplicate_labels=False)
tm.assert_frame_equal(result, expected)


class TestSeriesSetAxis(SharedSetAxisTests):
@pytest.fixture
Expand Down
Loading