-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
TST: DataFrameGroupBy.shift Loses TimeZone in datetime64 columns #30153
TST: DataFrameGroupBy.shift Loses TimeZone in datetime64 columns #30153
Conversation
Adding test case for issue GH30134
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.
Thanks for the PR! Looks good just a few edits
Can you also move this to pandas/tests/groupby/test_transform.py?
pandas/tests/dtypes/test_dtypes.py
Outdated
@@ -323,6 +324,13 @@ def test_tz_standardize(self): | |||
dtype = DatetimeTZDtype("ns", dr[0].tz) | |||
assert dtype.tz == tz | |||
|
|||
def test_dfgroupby_shift_tz(self): | |||
# GH 30134 | |||
df = pd.DataFrame({"a": [1, 1], "date": dt.datetime.now(tz=pytz.utc)}) |
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.
df = pd.DataFrame({"a": [1, 1], "date": dt.datetime.now(tz=pytz.utc)}) | |
df = pd.DataFrame({"a": [1, 1], "date": pd.Timestamp.utcnow()}) |
Slightly more idiomatic
pandas/tests/dtypes/test_dtypes.py
Outdated
df = pd.DataFrame({"a": [1, 1], "date": dt.datetime.now(tz=pytz.utc)}) | ||
expected = df.dtypes["date"] | ||
result = df.groupby("a").shift(0).dtypes["date"] | ||
assert expected == result |
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 build the actual expected series and use tm.assert_series_equal(result, expected)
? Should see examples of this throughout tests
@@ -1138,3 +1138,12 @@ def func(grp): | |||
|
|||
expected = pd.DataFrame([2, -2, 2, 4], columns=["B"]) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
|
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 move to pandas/tests/groupby/test_groupby.py, near the other _shift tests
lgtm ping on green |
Thanks @tranctan |
Adding test case for issue GH30134