Repository: pandas-dev/pandas
File: pandas/tests/frame/test_api.py (Python)

Code before:
            assert np.may_share_memory(obj["A"].values, result["A"].values)

        result.iloc[key] = 0
        assert obj.iloc[key] == 1

        # Now we do copy.
        result = obj.set_flags(allows_duplicate_labels=allows_duplicate_labels)
        result.iloc[key] = 10
        assert obj.iloc[key] == 1

    def test_constructor_expanddim(self):
        # GH#33628 accessing _constructor_expanddim should not raise NotImplementedError
        # GH38782 pandas has no container higher than DataFrame (two-dim), so
        # DataFrame._constructor_expand_dim, doesn't make sense, so is removed.
        df = DataFrame()

        msg = "'DataFrame' object has no attribute '_constructor_expanddim'"
        with pytest.raises(AttributeError, match=msg):
            df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))

    def test_inspect_getmembers(self):
        # GH38740
        df = DataFrame()
        inspect.getmembers(df)

    def test_setitem_series_alignment_documentation(self):
        # Test that Series assignment aligns by index as documented.
        df = DataFrame({"A": [1, 2, 3]}, index=[0, 1, 2])
        s = Series([10, 20], index=[1, 3])
        df["B"] = s
        expected = DataFrame({"A": [1, 2, 3], "B": [np.nan, 10, np.nan]})
        tm.assert_frame_equal(df, expected)

    def test_setitem_series_partial_alignment(self):
        # Test Series assignment with partial index match. """
        df = DataFrame({"A": [1, 2, 3, 4]}, index=["a", "b", "c", "d"])
        s = Series([100, 200], index=["b", "d"])
        df["B"] = s
        expected = DataFrame(
            {"A": [1, 2, 3, 4], "B": [np.nan, 100, np.nan, 200]},
            index=["a", "b", "c", "d"],
        )
        tm.assert_frame_equal(df, expected)


Review comment (suggestion):
I definitely appreciate you adding tests, but since this is a documentation change you shouldn't need to add anything here. Feel free to remove

Code after:
        obj = DataFrame({"A": [1, 2]})
        key = (0, 0)
        if frame_or_series is Series:
            obj = obj["A"]
            key = 0

        result = obj.set_flags(allows_duplicate_labels=allows_duplicate_labels)

        if allows_duplicate_labels is None:
            # We don't update when it's not provided
            assert result.flags.allows_duplicate_labels is True
        else:
            assert result.flags.allows_duplicate_labels is allows_duplicate_labels

        # We made a copy
        assert obj is not result

        # We didn't mutate obj
        assert obj.flags.allows_duplicate_labels is True

        # But we didn't copy data
        if frame_or_series is Series:
            assert np.may_share_memory(obj.values, result.values)
        else:
            assert np.may_share_memory(obj["A"].values, result["A"].values)

        result.iloc[key] = 0
        assert obj.iloc[key] == 1

        # Now we do copy.
        result = obj.set_flags(allows_duplicate_labels=allows_duplicate_labels)
        result.iloc[key] = 10
        assert obj.iloc[key] == 1

    def test_constructor_expanddim(self):
        # GH#33628 accessing _constructor_expanddim should not raise NotImplementedError
        # GH38782 pandas has no container higher than DataFrame (two-dim), so
        # DataFrame._constructor_expand_dim, doesn't make sense, so is removed.
        df = DataFrame()

        msg = "'DataFrame' object has no attribute '_constructor_expanddim'"
        with pytest.raises(AttributeError, match=msg):
            df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))

    def test_inspect_getmembers(self):
        # GH38740
        df = DataFrame()
        inspect.getmembers(df)