Skip to content

TST: Additional tests to iloc setitem #46419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1188,6 +1190,24 @@ 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):

# 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"],
},
dtype=object,
)
tm.assert_frame_equal(df, expected)


class TestILocErrors:
# NB: this test should work for _any_ Series we can pass as
Expand Down Expand Up @@ -1363,6 +1383,24 @@ def test_frame_iloc_setitem_callable(self):
exp.iloc[[1, 3], [0]] = [-5, -5]
tm.assert_frame_equal(res, exp)

def test_frame_iloc_setitem_callable_multicolumn_to_datetime(self):

# GH#20511
df = DataFrame({"A": ["2022-01-01", "2022-01-02"], "B": ["2021", "2022"]})

df.iloc[:, [0]] = df.iloc[:, [0]].apply(to_datetime)
expected = DataFrame(
{
"A": [
Timestamp("2022-01-01 00:00:00"),
Timestamp("2022-01-02 00:00:00"),
],
"B": ["2021", "2022"],
},
dtype=object,
)
tm.assert_frame_equal(df, expected)


class TestILocSeries:
def test_iloc(self):
Expand Down