Skip to content
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

Merged
merged 8 commits into from Dec 11, 2019

Conversation

tranctan
Copy link
Contributor

@tranctan tranctan commented Dec 9, 2019

Adding test case for issue GH30134

Copy link
Member

@WillAyd WillAyd left a 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?

@@ -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)})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

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
Copy link
Member

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

@WillAyd WillAyd added Groupby Testing pandas testing functions or related to the test suite Timezones Timezone data dtype labels Dec 9, 2019
@@ -1138,3 +1138,12 @@ def func(grp):

expected = pd.DataFrame([2, -2, 2, 4], columns=["B"])
tm.assert_frame_equal(result, expected)


Copy link
Contributor

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

@jreback jreback added this to the 1.0 milestone Dec 10, 2019
@jreback
Copy link
Contributor

jreback commented Dec 10, 2019

lgtm ping on green

@simonjayhawkins simonjayhawkins merged commit c3ee0c3 into pandas-dev:master Dec 11, 2019
@simonjayhawkins
Copy link
Member

Thanks @tranctan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Testing pandas testing functions or related to the test suite Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrameGroupBy.shift Loses TimeZone in datetime64 columns
4 participants