Skip to content

Commit 3c1ae7b

Browse files
committed
add test for issue #50942
1 parent 46ed6b1 commit 3c1ae7b

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+
"obj",
263+
[
264+
DataFrame({"A": [datetime(2025, 10, 30)]}),
265+
DataFrame({"A": [Timestamp(2025, 10, 30)] * 2}),
266+
DataFrame({"A": [Timedelta(1)]}),
267+
DataFrame({"A": [Timedelta(1), Timedelta(2)]}),
268+
],
269+
)
270+
def test_loc_empty_slice_assignment_with_datetime(self, obj):
271+
# issue #50942
272+
# empty slice assignment with datetime or timedelta should not raise exceptions
273+
mask = [False] * len(obj)
274+
try:
275+
obj.loc[mask] = obj
276+
assert True
277+
except Exception:
278+
pytest.fail("loc empty slice assignment raised Exception unexpectedly!")
279+
261280

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

0 commit comments

Comments
 (0)