Skip to content

TST: Assign back multiple column to datetime #46982

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

Merged
merged 4 commits into from
Jun 5, 2022
Merged
Changes from 2 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,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
Expand Down Expand Up @@ -1363,6 +1382,25 @@ 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is needed? It looks similar to the other test.

Copy link
Contributor Author

@parthi-siva parthi-siva May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used apply to convert to datetime. Yeah it's kind of look similar. Removed

self, using_array_manager
):

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


class TestILocSeries:
def test_iloc(self):
Expand Down