Skip to content

Commit e0398c4

Browse files
authored
BUG: empty slice assignment raises if datetime column is present #50942 (#62934)
1 parent c7db90f commit e0398c4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/indexing/test_loc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,25 @@ def test_loc_getitem_single_boolean_arg(self, obj, key, exp):
258258
else:
259259
assert res == exp
260260

261+
@pytest.mark.parametrize(
262+
"data",
263+
[
264+
[datetime(2025, 10, 30)],
265+
[Timestamp(2025, 10, 30)] * 2,
266+
[Timedelta(1)],
267+
[Timedelta(1), Timedelta(2)],
268+
],
269+
)
270+
def test_loc_empty_slice_assignment_with_datetime(self, data):
271+
# issue #50942
272+
# empty slice assignment with datetime or timedelta should not raise exceptions
273+
mask = [False] * len(data)
274+
275+
df = DataFrame(data=data, columns=["A"])
276+
expected = df.copy()
277+
df.loc[mask] = df
278+
tm.assert_frame_equal(df, expected)
279+
261280

262281
class TestLocBaseIndependent:
263282
# Tests for loc that do not depend on subclassing Base

0 commit comments

Comments
 (0)