Skip to content

Commit ba9b41d

Browse files
committed
Remove comment, add test case, move file
1 parent 997f50d commit ba9b41d

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
date_range,
3030
isna,
3131
notna,
32+
to_datetime,
3233
)
3334
import pandas._testing as tm
3435

@@ -1454,6 +1455,32 @@ def test_loc_bool_multiindex(self, dtype, indexer):
14541455
)
14551456
tm.assert_frame_equal(result, expected)
14561457

1458+
@pytest.mark.parametrize("utc", [False, True])
1459+
@pytest.mark.parametrize("column_label_array", [False, True])
1460+
def test_loc_datetime_assignment_dtype_does_not_change(
1461+
self, utc, column_label_array
1462+
):
1463+
# GH#49837
1464+
df = DataFrame(
1465+
{
1466+
"date": to_datetime(
1467+
[datetime(2022, 1, 20), datetime(2022, 1, 22)], utc=utc
1468+
),
1469+
"update": [True, False],
1470+
}
1471+
)
1472+
expected = df.copy(deep=True)
1473+
1474+
update_df = df[df["update"]]
1475+
1476+
column = "date"
1477+
if column_label_array:
1478+
column = [column]
1479+
1480+
df.loc[df["update"], column] = update_df["date"]
1481+
1482+
tm.assert_frame_equal(df, expected)
1483+
14571484

14581485
class TestDataFrameIndexingUInt64:
14591486
def test_setitem(self, uint64_frame):

pandas/tests/indexing/test_loc.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,28 +2971,6 @@ def test_loc_periodindex_3_levels():
29712971
assert mi_series.loc[(p_index[0], "A", "B")] == 1.0
29722972

29732973

2974-
@pytest.mark.parametrize("utc", [False, True])
2975-
def test_loc_datetime_assignment_dtype_does_not_change(utc):
2976-
# GH#49837
2977-
df = DataFrame(
2978-
{
2979-
# Checking with and without UTC as the original bug didn't occur
2980-
# for utc=True
2981-
"date": to_datetime(
2982-
[datetime(2022, 1, 20), datetime(2022, 1, 22)], utc=utc
2983-
),
2984-
"update": [True, False],
2985-
}
2986-
)
2987-
# We don't expect the dataframe to be changes at all
2988-
expected = df.copy(deep=True)
2989-
2990-
update_df = df[df["update"]]
2991-
df.loc[df["update"], ["date"]] = update_df["date"]
2992-
2993-
tm.assert_frame_equal(df, expected)
2994-
2995-
29962974
class TestLocSeries:
29972975
@pytest.mark.parametrize("val,expected", [(2**63 - 1, 3), (2**63, 4)])
29982976
def test_loc_uint64(self, val, expected):

0 commit comments

Comments
 (0)