diff --git a/pandas/tests/frame/methods/test_rename_axis.py b/pandas/tests/frame/methods/test_rename_axis.py index dd4a77c6509b8..feb83524cc2bb 100644 --- a/pandas/tests/frame/methods/test_rename_axis.py +++ b/pandas/tests/frame/methods/test_rename_axis.py @@ -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"] + ) + tm.assert_frame_equal(result, expected, check_flags=False) + def test_rename_axis_raises(self): # GH#17833 df = DataFrame({"A": [1, 2], "B": [1, 2]}) diff --git a/pandas/tests/frame/methods/test_set_axis.py b/pandas/tests/frame/methods/test_set_axis.py index 7b75bcf4f348d..12f81588e81bf 100644 --- a/pandas/tests/frame/methods/test_set_axis.py +++ b/pandas/tests/frame/methods/test_set_axis.py @@ -112,6 +112,16 @@ 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"]) + tm.assert_frame_equal(result, expected, check_flags=False) + class TestSeriesSetAxis(SharedSetAxisTests): @pytest.fixture