Skip to content

Commit d05bdeb

Browse files
authored
Adding testcase for quartile performed on a timestamp column group by ( closes #33168 ) (#47575)
1 parent 4fddc41 commit d05bdeb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pandas/tests/groupby/test_quantile.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,38 @@ def test_columns_groupby_quantile():
343343
)
344344

345345
tm.assert_frame_equal(result, expected)
346+
347+
348+
def test_timestamp_groupby_quantile():
349+
# GH 33168
350+
df = DataFrame(
351+
{
352+
"timestamp": pd.date_range(
353+
start="2020-04-19 00:00:00", freq="1T", periods=100, tz="UTC"
354+
).floor("1H"),
355+
"category": list(range(1, 101)),
356+
"value": list(range(101, 201)),
357+
}
358+
)
359+
360+
result = df.groupby("timestamp").quantile([0.2, 0.8])
361+
362+
expected = DataFrame(
363+
[
364+
{"category": 12.8, "value": 112.8},
365+
{"category": 48.2, "value": 148.2},
366+
{"category": 68.8, "value": 168.8},
367+
{"category": 92.2, "value": 192.2},
368+
],
369+
index=pd.MultiIndex.from_tuples(
370+
[
371+
(pd.Timestamp("2020-04-19 00:00:00+00:00"), 0.2),
372+
(pd.Timestamp("2020-04-19 00:00:00+00:00"), 0.8),
373+
(pd.Timestamp("2020-04-19 01:00:00+00:00"), 0.2),
374+
(pd.Timestamp("2020-04-19 01:00:00+00:00"), 0.8),
375+
],
376+
names=("timestamp", None),
377+
),
378+
)
379+
380+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)