-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: empty slice assignment raises if datetime column is present #50942 #62934
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
base: main
Are you sure you want to change the base?
Conversation
pandas/tests/indexing/test_loc.py
Outdated
| DataFrame({"A": [datetime(2025, 10, 30)]}), | ||
| DataFrame({"A": [Timestamp(2025, 10, 30)] * 2}), | ||
| DataFrame({"A": [Timedelta(1)]}), | ||
| DataFrame({"A": [Timedelta(1), Timedelta(2)]}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you construct the DataFrame in the body of the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
| 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!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You can remove the
try/except - 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)
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.