Skip to content

Adding testcase for quartile performed on a timestamp column group by ( closes #33168 ) #47575

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

Merged
merged 6 commits into from
Jul 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pandas/tests/groupby/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,38 @@ def test_columns_groupby_quantile():
)

tm.assert_frame_equal(result, expected)


def test_timestamp_groupby_quantile():
# GH 33168
df = DataFrame(
{
"timestamp": pd.date_range(
start="2020-04-19 00:00:00", freq="1T", periods=100, tz="UTC"
).floor("1H"),
"category": list(range(1, 101)),
"value": list(range(101, 201)),
}
)

result = df.groupby("timestamp").quantile([0.2, 0.8])

expected = DataFrame(
[
{"category": 12.8, "value": 112.8},
{"category": 48.2, "value": 148.2},
{"category": 68.8, "value": 168.8},
{"category": 92.2, "value": 192.2},
],
index=pd.MultiIndex.from_tuples(
[
(pd.Timestamp("2020-04-19 00:00:00+00:00"), 0.2),
(pd.Timestamp("2020-04-19 00:00:00+00:00"), 0.8),
(pd.Timestamp("2020-04-19 01:00:00+00:00"), 0.2),
(pd.Timestamp("2020-04-19 01:00:00+00:00"), 0.8),
],
names=("timestamp", None),
),
)

tm.assert_frame_equal(result, expected)