-
-
Couldn't load subscription status.
- Fork 19.2k
TST: Add test for loc setitem with expansion preserving tz-aware dtype #62698
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?
Changes from all 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||
| datetime, | ||||||
| time, | ||||||
| timedelta, | ||||||
| timezone, | ||||||
| ) | ||||||
| import re | ||||||
|
|
||||||
|
|
@@ -2702,6 +2703,27 @@ def test_loc_indexer_length_one(self): | |||||
| df.loc[np.array([True], dtype=np.bool_), ["a"]] = df["b"].copy() | ||||||
| tm.assert_frame_equal(df, expected) | ||||||
|
|
||||||
| def test_loc_setitem_bool_mask_tzaware_scalar_with_expansion(self): | ||||||
| # GH#55423 | ||||||
|
|
||||||
| df = DataFrame([{"id": 1}, {"id": 2}, {"id": 3}]) | ||||||
| _time = datetime.fromtimestamp(1695887042, tz=timezone.utc) | ||||||
|
|
||||||
| df.loc[df.id >= 2, "time"] = _time | ||||||
|
|
||||||
| assert isinstance(df["time"].dtype, pd.DatetimeTZDtype) | ||||||
| assert str(df["time"].dtype.tz) == "UTC" | ||||||
|
|
||||||
| expected_time = Timestamp(_time) | ||||||
| expected = DataFrame( | ||||||
| { | ||||||
| "id": [1, 2, 3], | ||||||
| "time": [pd.NaT, expected_time, expected_time], | ||||||
|
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.
Suggested change
The issue is about the Python datetime type - we don't want to wrap it with |
||||||
| } | ||||||
| ) | ||||||
| expected["time"] = expected["time"].astype("datetime64[us, UTC]") | ||||||
|
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.
Suggested change
|
||||||
| tm.assert_frame_equal(df, expected) | ||||||
|
|
||||||
|
|
||||||
| class TestLocListlike: | ||||||
| @pytest.mark.parametrize("box", [lambda x: x, np.asarray, list]) | ||||||
|
|
||||||
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.