diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index c61f3c028f129..539b56667ee07 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -21,11 +21,13 @@ Interval, NaT, Series, + Timestamp, array, concat, date_range, interval_range, isna, + to_datetime, ) import pandas._testing as tm from pandas.api.types import is_scalar @@ -1196,6 +1198,23 @@ def test_iloc_getitem_int_single_ea_block_view(self): arr[2] = arr[-1] assert ser[0] == arr[-1] + def test_iloc_setitem_multicolumn_to_datetime(self, using_array_manager): + + # GH#20511 + df = DataFrame({"A": ["2022-01-01", "2022-01-02"], "B": ["2021", "2022"]}) + + df.iloc[:, [0]] = DataFrame({"A": to_datetime(["2021", "2022"])}) + expected = DataFrame( + { + "A": [ + Timestamp("2021-01-01 00:00:00"), + Timestamp("2022-01-01 00:00:00"), + ], + "B": ["2021", "2022"], + } + ) + tm.assert_frame_equal(df, expected, check_dtype=using_array_manager) + class TestILocErrors: # NB: this test should work for _any_ Series we can pass as