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

Code before:
        )
        tm.assert_frame_equal(result, expected)

    def test_reindex_single_column_ea_index_and_columns(self, any_numeric_ea_dtype):
        # GH#48190
        df = DataFrame({"a": [1, 2]}, dtype=any_numeric_ea_dtype)
        result = df.reindex(columns=list("ab"), index=[0, 1, 2], fill_value=10)
        expected = DataFrame(
            {"a": Series([1, 2, 10], dtype=any_numeric_ea_dtype), "b": 10}
        )
        tm.assert_frame_equal(result, expected)

    def test_reindex_multiple_columns_string_fill_value(self):
        # GH#63993
        df = DataFrame({"a": [0]})
        result = df.reindex(columns=["a", "b", "c"], fill_value="missing")

        # Should not raise AssertionError
        assert result.shape == (1, 3)
        assert result["a"].iloc[0] == 0
        assert result["b"].iloc[0] == "missing"
        assert result["c"].iloc[0] == "missing"

        # All string columns should have consistent str dtype
        assert result["b"].dtype == "str"
        assert result["c"].dtype == "str"

    def test_reindex_dups(self):
        # GH4746, reindex on duplicate index error messages
        arr = np.random.default_rng(2).standard_normal(10)
        df = DataFrame(arr, index=[1, 2, 3, 4, 5, 1, 2, 3, 4, 5])

        # set index is ok
        result = df.copy()
        result.index = list(range(len(df)))
        expected = DataFrame(arr, index=list(range(len(df))))
        tm.assert_frame_equal(result, expected)

        # reindex fails
        msg = "cannot reindex on an axis with duplicate labels"
        with pytest.raises(ValueError, match=msg):
            df.reindex(index=list(range(len(df))))

    def test_reindex_with_duplicate_columns(self):
        # reindex is invalid!
        df = DataFrame(
            [[1, 5, 7.0], [1, 5, 7.0], [1, 5, 7.0]], columns=["bar", "a", "a"]
        )
        msg = "cannot reindex on an axis with duplicate labels"
        with pytest.raises(ValueError, match=msg):
            df.reindex(columns=["bar"])

Review comment (suggestion):
Instead of asserting the individual values and dtypes, could you create the `expected = DataFrame(..)` and then assert_frame_equal(result, expected)

Code after:
        )
        tm.assert_frame_equal(result, expected)

    def test_reindex_single_column_ea_index_and_columns(self, any_numeric_ea_dtype):
        # GH#48190
        df = DataFrame({"a": [1, 2]}, dtype=any_numeric_ea_dtype)
        result = df.reindex(columns=list("ab"), index=[0, 1, 2], fill_value=10)
        expected = DataFrame(
            {"a": Series([1, 2, 10], dtype=any_numeric_ea_dtype), "b": 10}
        )
        tm.assert_frame_equal(result, expected)

    def test_reindex_with_string_fill_value(self):
        # GH#63993
        df = DataFrame({"a": [0]})
        result = df.reindex(columns=["a", "b", "c"], fill_value="missing")
        expected = DataFrame({"a": [0], "b": ["missing"], "c": ["missing"]})
        tm.assert_frame_equal(result, expected)

    def test_reindex_dups(self):
        # GH4746, reindex on duplicate index error messages
        arr = np.random.default_rng(2).standard_normal(10)
        df = DataFrame(arr, index=[1, 2, 3, 4, 5, 1, 2, 3, 4, 5])

        # set index is ok
        result = df.copy()
        result.index = list(range(len(df)))
        expected = DataFrame(arr, index=list(range(len(df))))
        tm.assert_frame_equal(result, expected)

        # reindex fails
        msg = "cannot reindex on an axis with duplicate labels"
        with pytest.raises(ValueError, match=msg):
            df.reindex(index=list(range(len(df))))

    def test_reindex_with_duplicate_columns(self):
        # reindex is invalid!
        df = DataFrame(
            [[1, 5, 7.0], [1, 5, 7.0], [1, 5, 7.0]], columns=["bar", "a", "a"]
        )
        msg = "cannot reindex on an axis with duplicate labels"
        with pytest.raises(ValueError, match=msg):
            df.reindex(columns=["bar"])
        with pytest.raises(ValueError, match=msg):
            df.reindex(columns=["bar", "foo"])

    def test_reindex_axis_style(self):
        # https://github.com/pandas-dev/pandas/issues/12392
        df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
        expected = DataFrame(
            {"A": [1, 2, np.nan], "B": [4, 5, np.nan]}, index=[0, 1, 3]