Skip to content

Commit d653961

Browse files
committed
testcase for pandas-dev#33168 Quantile function fails when performing groupby on Time Zone Aware Timestamps
1 parent 3e9aaf4 commit d653961

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pandas/tests/groupby/test_quantile.py

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

345345
tm.assert_frame_equal(result, expected)
346+
347+
def test_timestamp_groupby_quantile():
348+
# GH 33168
349+
df = DataFrame(
350+
{
351+
'timestamp': pd.date_range(start='2020-04-19 00:00:00', freq='1T', periods=200, tz='UTC').floor('1H'),
352+
'category': list(range(1, 201)),
353+
'value': list(range(201, 401))
354+
}
355+
)
356+
357+
result = df.groupby('timestamp').quantile([0.1, 0.5, 0.9])
358+
359+
expected = DataFrame(
360+
[
361+
{'category': 6.9, 'value': 206.9},
362+
{'category': 30.5, 'value': 230.5},
363+
{'category': 54.1, 'value': 254.1},
364+
{'category': 66.9, 'value': 266.9},
365+
{'category': 90.5, 'value': 290.5},
366+
{'category': 114.1, 'value': 314.1},
367+
{'category': 126.9, 'value': 326.9},
368+
{'category': 150.5, 'value': 350.5},
369+
{'category': 174.1, 'value': 374.1},
370+
{'category': 182.9, 'value': 382.9},
371+
{'category': 190.5, 'value': 390.5},
372+
{'category': 198.1, 'value': 398.1}
373+
],
374+
index=pd.MultiIndex.from_tuples(
375+
[
376+
( pd.Timestamp('2020-04-19 00:00:00+00:00'), 0.1),
377+
( pd.Timestamp('2020-04-19 00:00:00+00:00'), 0.5),
378+
( pd.Timestamp('2020-04-19 00:00:00+00:00'), 0.9),
379+
( pd.Timestamp('2020-04-19 01:00:00+00:00'), 0.1),
380+
( pd.Timestamp('2020-04-19 01:00:00+00:00'), 0.5),
381+
( pd.Timestamp('2020-04-19 01:00:00+00:00'), 0.9),
382+
( pd.Timestamp('2020-04-19 02:00:00+00:00'), 0.1),
383+
( pd.Timestamp('2020-04-19 02:00:00+00:00'), 0.5),
384+
( pd.Timestamp('2020-04-19 02:00:00+00:00'), 0.9),
385+
( pd.Timestamp('2020-04-19 03:00:00+00:00'), 0.1),
386+
( pd.Timestamp('2020-04-19 03:00:00+00:00'), 0.5),
387+
( pd.Timestamp('2020-04-19 03:00:00+00:00'), 0.9)
388+
], names=('timestamp', None)
389+
)
390+
)
391+
392+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)