-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
test: Add test for loc assignment changes datetime dtype #50037
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2971,6 +2971,28 @@ def test_loc_periodindex_3_levels(): | |
assert mi_series.loc[(p_index[0], "A", "B")] == 1.0 | ||
|
||
|
||
@pytest.mark.parametrize("utc", [False, True]) | ||
def test_loc_datetime_assignment_dtype_does_not_change(utc): | ||
# GH#49837 | ||
df = DataFrame( | ||
{ | ||
# Checking with and without UTC as the original bug didn't occur | ||
# for utc=True | ||
"date": to_datetime( | ||
[datetime(2022, 1, 20), datetime(2022, 1, 22)], utc=utc | ||
), | ||
"update": [True, False], | ||
} | ||
) | ||
# We don't expect the dataframe to be changes at all | ||
expected = df.copy(deep=True) | ||
|
||
update_df = df[df["update"]] | ||
df.loc[df["update"], ["date"]] = update_df["date"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, actually the bug didn't occur in the second one. BTW - is this the right place for the test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, better place is probably frame/indexing/test_indexing |
||
|
||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
class TestLocSeries: | ||
@pytest.mark.parametrize("val,expected", [(2**63 - 1, 3), (2**63, 4)]) | ||
def test_loc_uint64(self, val, expected): | ||
|
Uh oh!
There was an error while loading. Please reload this page.