Skip to content
Merged
Changes from 5 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/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,27 @@ def test_loc_getitem_single_boolean_arg(self, obj, key, exp):
else:
assert res == exp

@pytest.mark.parametrize(
"data",
[
[datetime(2025, 10, 30)],
[Timestamp(2025, 10, 30)] * 2,
[Timedelta(1)],
[Timedelta(1), Timedelta(2)],
],
)
def test_loc_empty_slice_assignment_with_datetime(self, data):
# issue #50942
# empty slice assignment with datetime or timedelta should not raise exceptions
mask = [False] * len(data)
try:
df = DataFrame(data=data, columns=["A"])
res = df.loc[mask]
res = df
tm.assert_frame_equal(res, df)
except Exception:
pytest.fail("loc empty slice assignment raised Exception unexpectedly!")
Copy link
Member

Choose a reason for hiding this comment

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

  1. You can remove the try/except
  2. In the original issue, it's testing a setitem, so this would need to be
expected = df.copy()
df.loc[mask] = df
tm.assert_frame_equal(df, expected) 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated



class TestLocBaseIndependent:
# Tests for loc that do not depend on subclassing Base
Expand Down
Loading