Skip to content

test: Add test for loc assignment changes datetime dtype #50037

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
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
21 changes: 21 additions & 0 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
date_range,
isna,
notna,
to_datetime,
)
import pandas._testing as tm

Expand Down Expand Up @@ -1454,6 +1455,26 @@ def test_loc_bool_multiindex(self, dtype, indexer):
)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("utc", [False, True])
@pytest.mark.parametrize("indexer", ["date", ["date"]])
def test_loc_datetime_assignment_dtype_does_not_change(self, utc, indexer):
# GH#49837
df = DataFrame(
{
"date": to_datetime(
[datetime(2022, 1, 20), datetime(2022, 1, 22)], utc=utc
),
"update": [True, False],
}
)
expected = df.copy(deep=True)

update_df = df[df["update"]]

df.loc[df["update"], indexer] = update_df["date"]

tm.assert_frame_equal(df, expected)


class TestDataFrameIndexingUInt64:
def test_setitem(self, uint64_frame):
Expand Down