Skip to content

Commit 9ac94f3

Browse files
parthi-sivayehoshuadimarsky
authored andcommitted
TST: Assign back multiple column to datetime (pandas-dev#46982)
1 parent 2eefc89 commit 9ac94f3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/indexing/test_iloc.py

+19
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
Interval,
2222
NaT,
2323
Series,
24+
Timestamp,
2425
array,
2526
concat,
2627
date_range,
2728
interval_range,
2829
isna,
30+
to_datetime,
2931
)
3032
import pandas._testing as tm
3133
from pandas.api.types import is_scalar
@@ -1196,6 +1198,23 @@ def test_iloc_getitem_int_single_ea_block_view(self):
11961198
arr[2] = arr[-1]
11971199
assert ser[0] == arr[-1]
11981200

1201+
def test_iloc_setitem_multicolumn_to_datetime(self, using_array_manager):
1202+
1203+
# GH#20511
1204+
df = DataFrame({"A": ["2022-01-01", "2022-01-02"], "B": ["2021", "2022"]})
1205+
1206+
df.iloc[:, [0]] = DataFrame({"A": to_datetime(["2021", "2022"])})
1207+
expected = DataFrame(
1208+
{
1209+
"A": [
1210+
Timestamp("2021-01-01 00:00:00"),
1211+
Timestamp("2022-01-01 00:00:00"),
1212+
],
1213+
"B": ["2021", "2022"],
1214+
}
1215+
)
1216+
tm.assert_frame_equal(df, expected, check_dtype=using_array_manager)
1217+
11991218

12001219
class TestILocErrors:
12011220
# NB: this test should work for _any_ Series we can pass as

0 commit comments

Comments
 (0)